Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:44115 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3263 invoked from network); 1 Jun 2009 11:34:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Jun 2009 11:34:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=nrixham@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nrixham@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.214 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: nrixham@gmail.com X-Host-Fingerprint: 209.85.219.214 mail-ew0-f214.google.com Received: from [209.85.219.214] ([209.85.219.214:63660] helo=mail-ew0-f214.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A8/C9-52049-1ECB32A4 for ; Mon, 01 Jun 2009 07:34:58 -0400 Received: by ewy10 with SMTP id 10so8341873ewy.23 for ; Mon, 01 Jun 2009 04:34:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=tifw4SKXwLQ+O/VqKJABqoz835GQjzHAfxfbqELResU=; b=t8XJRRks6HNX3j9Uw+Ot2993ASALispL42SrU+ZBlAFquZYuQzlasWP/GDTGD8wWAw fc1iaaXVAda3lh5+eUp+u60n5gIJ9gbSwp93+Uu1xmGnkZ45vfjooab+WWsK1QifID5n mRCv361llTAm1ZrUp7IE0PPAymgoIhkIwsD1Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=TfqEAVjs9NCoqJTgzaf/7OVPrLUJGnn9x+6DQCYKUzikSync5ysi1jL2xZdxl2PzXQ 8WVZKxUfMQAau3/xosn8q039/rxKxEdFNA/VUoQEFzYJrjcKjZgapTA88XcNPT+YbXGp ROu75bQCwynyBZrH/BfymkLzohLuazJHIf1Ao= Received: by 10.210.119.5 with SMTP id r5mr2807167ebc.1.1243856094484; Mon, 01 Jun 2009 04:34:54 -0700 (PDT) Received: from ?192.168.2.5? (82-41-135-70.cable.ubr02.grth.blueyonder.co.uk [82.41.135.70]) by mx.google.com with ESMTPS id 5sm8455091ewy.52.2009.06.01.04.34.53 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 01 Jun 2009 04:34:53 -0700 (PDT) Message-ID: <4A23BCDC.3080702@gmail.com> Date: Mon, 01 Jun 2009 12:34:52 +0100 User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) MIME-Version: 1.0 To: Jonathan Tapicer CC: internals@lists.php.net, Matt Wilson References: <32074276-E941-45C8-B1A1-9A6EB34F4D7E@gmail.com> <4A23330D.4000205@gmail.com> <8F0784FF-AD51-4A97-9C3A-6B4A3F45D260@gmail.com> <4A23367A.9070804@gmail.com> <4603e2db0905311920q7681519j8f4b87a2c71e20cd@mail.gmail.com> In-Reply-To: <4603e2db0905311920q7681519j8f4b87a2c71e20cd@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] need inverted __sleep? From: nrixham@gmail.com (Nathan Rixham) 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