Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:44112 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 34018 invoked from network); 1 Jun 2009 02:20:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Jun 2009 02:20:49 -0000 Authentication-Results: pb1.pair.com smtp.mail=tapicer@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tapicer@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.173 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: tapicer@gmail.com X-Host-Fingerprint: 209.85.217.173 mail-gx0-f173.google.com Received: from [209.85.217.173] ([209.85.217.173:40533] helo=mail-gx0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4E/08-20810-00B332A4 for ; Sun, 31 May 2009 22:20:49 -0400 Received: by gxk21 with SMTP id 21so101471gxk.23 for ; Sun, 31 May 2009 19:20:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=ZHGittsSEcG3k/o8428ki7yOXVL/OR4shNaBAzYgoV4=; b=aTLEmCr7ZFAK/xqLEOSoaE+OI1hdFPgEveBV6tkg091y4gO+j+w9fvZ2foAJlkGe2n uZnB+9boERpQjmFQiQ2O2BEGn3v7pQYoLbQXS00NwiJJwpkeTQ2UtA/C2rNcZ0CiNPyk QQL5vh4wKfTNbRXKtrPi49VGZRgSNDMeNsJSY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=tNiLPTU6Q3iub9NBCrQSu61Sh83HSaUhKT3L4KUpzd2m7m6ntMQYoKu2hI+LXGbswz f8JNT7wUyJ53Ef6fLN5njizU7b551zo4KOYoJR5Iu8jW+S0kwdMp4/waQLvpUUq1w1wK +4YpRwFYD9fHrXa6UDw6X7NKZscztsYA26P10= MIME-Version: 1.0 Received: by 10.151.137.2 with SMTP id p2mr10614566ybn.101.1243822845592; Sun, 31 May 2009 19:20:45 -0700 (PDT) In-Reply-To: <4A23367A.9070804@gmail.com> References: <32074276-E941-45C8-B1A1-9A6EB34F4D7E@gmail.com> <4A23330D.4000205@gmail.com> <8F0784FF-AD51-4A97-9C3A-6B4A3F45D260@gmail.com> <4A23367A.9070804@gmail.com> Date: Sun, 31 May 2009 23:20:45 -0300 Message-ID: <4603e2db0905311920q7681519j8f4b87a2c71e20cd@mail.gmail.com> To: Nathan Rixham Cc: internals@lists.php.net, Matt Wilson Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] need inverted __sleep? From: tapicer@gmail.com (Jonathan Tapicer) 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 On Sun, May 31, 2009 at 11:01 PM, Nathan Rixham wrote: > matt.. that's public properties on a single class - see the usecase > > use case: > class base > { > =A0private $notToBeSerialized; > > =A0public function __sleep() > =A0{ > =A0 =A0// TODO code return instance properties excluding $notToBeSerializ= ed > =A0} > > } > > class foo extends base > { > =A0private $bar; > } > > class poo extends foo > { > =A0private $baz; > } > > $p =3D new poo; > echo serialize($p); > > > Matt Wilson wrote: >> >> mwilson@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 =3D new a; var_dump($a->__sleep());' >> array(2) { >> =A0[0]=3D> >> =A0string(1) "a" >> =A0[3]=3D> >> =A0string(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: >>>>> >>>> class base >>>>> { >>>>> private $notToBeSerialized; >>>>> >>>>> public function __sleep() >>>>> { >>>>> =A0// TODO code return instance properties excluding $notToBeSerializ= ed >>>>> } >>>>> >>>>> } >>>>> >>>>> class foo extends base >>>>> { >>>>> private $bar; >>>>> } >>>>> >>>>> class poo extends foo >>>>> { >>>>> private $baz; >>>>> } >>>>> >>>>> $p =3D 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 t= o >>>>> serialize($this) then parse the string, but that's just wrong and wha= t 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 > >