Catchable fatal error: Object of class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Catchable fatal error: Object of class

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

use $d->path when you need to perform string operations on a directory.
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

Would path be

Code: Select all

$direktori.'/'.$avatarcategory
?
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

What's the point of using obsolete dir class? scandir() , glob() (and DirectoryIterator for OOP fans) are your friends.
Post Reply