Re: Internal Serializable object. Hack to create an object without constructor

From: Date: Tue, 17 Jun 2014 07:47:52 +0000
Subject: Re: Internal Serializable object. Hack to create an object without constructor
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-74931@lists.php.net to get a copy of this message
On Sat, Jun 14, 2014 at 9:40 AM, Ferenc Kovacs <tyra3l@gmail.com> wrote: > On Thu, Jun 12, 2014 at 1:48 PM, Remi Collet <remi@fedoraproject.org> wrote: > >> Hi, >> >> As Internal Class doesn't support newInstanceWithoutConstructor, some >> user code use the above hack (ex phpunit-mock-object) >> >> $object = unserialize( >> sprintf('%s:%d:"%s":0:{}', >> (version_compare(PHP_VERSION, '5.4', '>') >> && $class->implementsInterface("Serializable") ? "C" >> : "O"), >> strlen($className), >> $className >> ) >> ); >> >> Of course, this is already a hack. >> >> Of course, better solution will be to support >> newInstanceWithoutConstructor for all internals classes, but this is >> another story >> >> Problem, Serializable internal class raised the >> 'Empty serialized string cannot be empty' exception. >> >> I don't really see any reason to make serialized string mandatory, as >> those classes can be create (constructor) without any mandatory option. >> >> The trivial attached patch could make everyone life easier. >> >> The new test serialize again the result object to ensure all internal >> structures are properly initialized, and no segfault. >> >> >> Feedback welcome. >> >> >> Remi. >> >> -- >> 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 >> > > I'm +1 on this change, would like to hear what others think. > > ps: small typo in the patch: > Check that SplObjectStorage::unserialize desn't throws exception when NULL > passed > should be > Check that SplObjectStorage::unserialize doesn't throw exception when NULL > passed > imo I'm also +1, but better wait for Etienne's answer about those strings. If he used such a code, I guess there was a reason, if we effectively can get rid of them with no hidden bug, then go for it Julien P

« previous php.internals (#74931) next »