mwil...@mattw-mac:~$ php -r 'class a { public $a, $b, $c, $d; public function __sleep() { return array_diff( array_keys( (array) $this), array("b","c")); } } $a = new a; var_dump($a->__sleep());'
array(2) {
  [0]=>
  string(1) "a"
  [3]=>
  string(1) "d"
}

On May 31, 2009, at 8:46 PM, Nathan Rixham wrote:

Matt Wilson wrote:
get_class_vars + array_diff

cheers but nope; as the manual says
"Returns an associative array of default public properties of the class"

need private and inherited private

On May 31, 2009, at 8:04 PM, Nathan Rixham wrote:
Hi All,

hoping somebody can help me here..

I need to implement an inverted __sleep method, by which I mean to specify what variables should not be included.

use case:
<?php
class base
{
private $notToBeSerialized;

public function __sleep()
{
// TODO code return instance properties excluding $notToBeSerialized
}

}

class foo extends base
{
private $bar;
}

class poo extends foo
{
private $baz;
}

$p = new poo;
echo serialize($p);

----

I've tried using get_object_vars($this), and ReflectionObject($this) both of which don't include all the properties of the instance.

the only way I can see to get all the properties of the instance is to serialize($this) then parse the string, but that's just wrong and what would sleep return on the first call to serialize.

any help greatly appreciated.

regards,

nathan

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to