Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:74931 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64312 invoked from network); 17 Jun 2014 07:48:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jun 2014 07:48:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=julienpauli@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=julienpauli@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.175 as permitted sender) X-PHP-List-Original-Sender: julienpauli@gmail.com X-Host-Fingerprint: 209.85.128.175 mail-ve0-f175.google.com Received: from [209.85.128.175] ([209.85.128.175:34909] helo=mail-ve0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 75/70-59176-3D2FF935 for ; Tue, 17 Jun 2014 03:48:36 -0400 Received: by mail-ve0-f175.google.com with SMTP id jx11so4385728veb.6 for ; Tue, 17 Jun 2014 00:48:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=eKqDEiyRh4yVHsqutZvOY9u4rRsPhrvdwY2fC33eRNk=; b=guTLxkewTjjV0wkz37/GB0YbaHbBI4m4rT+TGrYTjrZjI9T6QqWZ13svFOZoY8PNhH LSu4TJGo8+84y00AUm93M5hLZuryZhzBudqV41pn8xNjGW7xPhwQLeC9iPG5aSkyfl7d PLvtGIBw3ImWZHZzwMIE439BwC00ys0uOwEde4m8Abd3HS2M0e6r1QXkhz00eG+C2SAP 74Ub+VXm+jqgq5m+HYWn6lni+xJmC2Q0uJ9MYpW9UyZlpL9COQqBoSvN3PRlQPU5R1uj rfG3q1EZT1zIaT3fPB90+aT6twjtITmKvis51gRgsDQ9aVZY6PdEb2k/amAZkbcRVI/j acIw== X-Received: by 10.58.109.71 with SMTP id hq7mr9055311veb.26.1402991313173; Tue, 17 Jun 2014 00:48:33 -0700 (PDT) MIME-Version: 1.0 Sender: julienpauli@gmail.com Received: by 10.220.81.68 with HTTP; Tue, 17 Jun 2014 00:47:52 -0700 (PDT) In-Reply-To: References: <53999376.8070807@fedoraproject.org> Date: Tue, 17 Jun 2014 09:47:52 +0200 X-Google-Sender-Auth: 9bXttWpblRWVSD_XSsHUINIjaW0 Message-ID: To: Ferenc Kovacs Cc: Remi Collet , PHP internals , Sebastian Bergmann Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Internal Serializable object. Hack to create an object without constructor From: jpauli@php.net (Julien Pauli) On Sat, Jun 14, 2014 at 9:40 AM, Ferenc Kovacs wrote: > On Thu, Jun 12, 2014 at 1:48 PM, Remi Collet 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