Page 1 of 1

Catchable fatal error: Object of class

Posted: Wed Apr 18, 2007 7:15 pm
by SidewinderX

Code: Select all

$d = dir("$direktori/$avatarcategory");
while (false !== ($entry = $d->read())) {
    if( preg_match('/(\.gif$|\.png$|\.jpg|\.jpeg)$/is', $entry) ) {
        if( $entry != '.' && $entry != '..' && !is_file($d . '/' . $entry) && !is_link($d . '/' . $entry) ) {
            $patterns[0] = "/\.gif/";
            $patterns[1] = "/\.png/";
            $patterns[2] = "/\.jpg/";
            //more code
        }
    //more code
    }
//more code
}
The fourth line gives me the error

Code: Select all

Catchable fatal error: Object of class Directory could not be converted to string ....
by removing this from the third line in the above code

Code: Select all

&& !is_file($d . '/' . $entry) && !is_link($d . '/' . $entry)
the code doesn't give me the error, but that code is obviously there for a reason. Other than switching to a PHP < 5.2 how can I fix this problem?

Posted: Wed Apr 18, 2007 7:24 pm
by Weirdan
use $d->path when you need to perform string operations on a directory.

Posted: Wed Apr 18, 2007 7:37 pm
by SidewinderX
Would path be

Code: Select all

$direktori.'/'.$avatarcategory
?

Posted: Thu Apr 19, 2007 4:10 am
by stereofrog
What's the point of using obsolete dir class? scandir() , glob() (and DirectoryIterator for OOP fans) are your friends.