Jonathan Tapicer wrote:
Hi,
Matt's approach works also for your usecase, casting to array returns
all the properties of the class and base classes, but it has some
problems: for private properties the class name is added before the
property name, and for protected properties * is added, both things
added are between null characters, so you can remove the added string
with some regexp.
Another approach that will work is using ReflectionClass and the
method getProperties, it will return all the properties (even
private), but only of the class itself, it won't return the properties
declared in base classes, you have the get the base class
(get_parent_class) and recursively do the same thing for all the base
classes.
Regards,
Jonathan
doh, thanks Jonathan and thanks Matt - completely missed that (array)
even though I'd been using it in a different attempt using Serializable
small note is that you do not need to remove the class names or
suchlike, this works fine (and I assume is faster than recursive reflection)
public function __sleep()
{
$exclude = chr(0) . __CLASS__ . chr(0) . 'notToBeSerialized';
return array_diff(array_keys((array)$this) , array($exclude) );
}
again thanks, and apologies Matt!
Regards,
Nathan
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php