Re: [PATCH] Make var_export() output "(object)array(..." instead of "stdClass::__set_state(..." for stdClass

From: Date: Tue, 14 Mar 2017 22:59:35 +0000
Subject: Re: [PATCH] Make var_export() output "(object)array(..." instead of "stdClass::__set_state(..." for stdClass
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-98525@lists.php.net to get a copy of this message
On Tue, Mar 14, 2017 at 11:20 PM, Derick Rethans <derick@php.net> wrote: > On Tue, 14 Mar 2017, 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? > > As original author of var_export, I approve of this — including not > adding __set_state(). > > cheers, > Derick > I'm also +1 on this, and also prefer not having __set_state(). An object cast is both more idiomatic and more performant. Additionally I feel that adding methods to stdClass will muddy the waters -- for example, this means that extending stdClass is no longer entirely unreasonable, as you might want to do it to reuse the __set_state() implementation. Not something I want to see happening. Nikita

« previous php.internals (#98525) next »