"Object with no values or functions"

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
del
Forum Newbie
Posts: 3
Joined: Sat Oct 14, 2006 3:57 pm

"Object with no values or functions"

Post by del »

I was just casually browsing the 2nd edition of "Programming PHP" from O'Reilly and in the section regarding what evaluates to false it states "An object with no values or functions". But when I test this with:

Code: Select all

class EmptyClass {}
assert(new EmptyClass() == false);
The assertion fails.

Is this an error in the book?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

http://www.php.net/manual/en/language.t ... an.casting
When converting to boolean, the following values are considered FALSE:
...
an object with zero member variables (PHP 4 only)
Do you use php5?
del
Forum Newbie
Posts: 3
Joined: Sat Oct 14, 2006 3:57 pm

Post by del »

Yes I do. I guess the book (which supposedly covers PHP5) wasn't updated properly in this section or something.

Thanks.
Post Reply