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
ed209
Forum Contributor
Posts: 153 Joined: Thu May 12, 2005 5:06 am
Location: UK
Post
by ed209 » Tue Apr 17, 2007 3:28 pm
As of PHP 5, objects with no properties are no longer considered empty.
So,
Code: Select all
if ( !empty( $myObject ) ) {
// object not empty
}
will not work - even if it is empty. Is there a way around this?
ed209
Forum Contributor
Posts: 153 Joined: Thu May 12, 2005 5:06 am
Location: UK
Post
by ed209 » Tue Apr 17, 2007 3:54 pm
so something like:
Code: Select all
if ( !count(get_object_vars( $myObject )) ) {
// object is empty
}
I think the PHP4 method was nicer! Thanks for the reply.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Tue Apr 17, 2007 3:59 pm
I'm actually not sure how it plays with protected and private properties, so you may have to test that. Better yet, let us know of the results.
If all else fails, theres always Reflection.
ed209
Forum Contributor
Posts: 153 Joined: Thu May 12, 2005 5:06 am
Location: UK
Post
by ed209 » Tue Apr 17, 2007 4:08 pm
I'm afraid you lost me
The above does work for what I need though, thanks. My object is pretty simple, just a load of $_POSTed values put into an object.