Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98523 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87829 invoked from network); 14 Mar 2017 20:01:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Mar 2017 20:01:14 -0000 Authentication-Results: pb1.pair.com smtp.mail=dev@mabe.berlin; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=dev@mabe.berlin; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mabe.berlin from 80.237.132.167 cause and error) X-PHP-List-Original-Sender: dev@mabe.berlin X-Host-Fingerprint: 80.237.132.167 wp160.webpack.hosteurope.de Received: from [80.237.132.167] ([80.237.132.167:35748] helo=wp160.webpack.hosteurope.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7D/08-38004-40C48C85 for ; Tue, 14 Mar 2017 15:01:11 -0500 Received: from dslb-094-222-208-139.094.222.pools.vodafone-ip.de ([94.222.208.139] helo=[192.168.178.53]); authenticated by wp160.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) id 1cnscz-0003Cm-4L; Tue, 14 Mar 2017 21:01:05 +0100 To: internals@lists.php.net References: <04.57.38004.22D38C85@pb1.pair.com> Message-ID: <156faa4f-b159-031d-23a2-7367f692dce0@mabe.berlin> Date: Tue, 14 Mar 2017 21:01:04 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-bounce-key: webpack.hosteurope.de;dev@mabe.berlin;1489521671;a9517a8a; X-HE-SMSGID: 1cnscz-0003Cm-4L Subject: Re: [PHP-DEV] [PATCH] Make var_export() output "(object)array(..." instead of "stdClass::__set_state(..." for stdClass From: dev@mabe.berlin (Marc Bennewitz) Am 14.03.2017 um 20:26 schrieb Fleshgrinder: > On 3/14/2017 7:57 PM, Andrea Faulds wrote: >> Hi everyone, >> >> Since stdClass has no __set_state method, var_export() produces unusable >> output if given an object of that class. I wrote a patch that would make >> var_export() produce a cast to object instead, which could be evaluated >> to get back a stdClass: >> >> https://github.com/php/php-src/pull/2420 >> >> Any thoughts/comments? >> >> If you're wondering about whether a __set_state method should be added >> to stdClass, I posted some thoughts in the pull request discussion already. >> >> Thanks! > > I actually already used __set_state occasionally for userland classes. > Adding __set_state to stdClass seems to be more consistent with the rest > of PHP, rather than special casing it in one method. I cannot see any > issues with this to be honest. > Personally I would like to have a more reasonable way in general. No special case and no magic method. So my proposal then would be to try to add a class cast operator (needs an own RFC) and later to with this approach on var_export. Example: class Foo {} $std = new stdClass; $foo = new Foo; $arr = ['arr' => 'arr']; var_dump((object)$std); // no change var_dump((array)$std); // no change var_dump((Foo)$std); // object of class Foo var_dump((object)$foo); // no change var_dump((stdClass)$foo); // object of class stdClass var_dump((array)$foo); // no change var_dump((array)$arr); // no change var_dump((object)$arr); // no change var_dump((stdClass)$arr); // object of class stdClass var_dump((Foo)$arr); // object of class Foo Thoughts? Marc