Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:59467 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81937 invoked from network); 8 Apr 2012 16:38:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Apr 2012 16:38:12 -0000 Authentication-Results: pb1.pair.com smtp.mail=reeze.xia@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=reeze.xia@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.210.170 as permitted sender) X-PHP-List-Original-Sender: reeze.xia@gmail.com X-Host-Fingerprint: 209.85.210.170 mail-iy0-f170.google.com Received: from [209.85.210.170] ([209.85.210.170:46610] helo=mail-iy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 89/A4-56433-3FEB18F4 for ; Sun, 08 Apr 2012 12:38:11 -0400 Received: by iaeh11 with SMTP id h11so6021017iae.29 for ; Sun, 08 Apr 2012 09:38:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:message-id:subject:x-mailer:mime-version:content-type; bh=672RQrtbkaF5rQGC90R23vuHWxrfF1a93GgFYMwxO2U=; b=VCJNSgRBrzDbCb5zo0rEJoJ3pg/YNf1AWeP701hf78lyIEIkhGxzu9Ra7d9FlWAx8l lcq+rZbZNwP7fdqpomCK0iZ3qiUOroxAkHiWO+aztz8nagDI09QgO2JkWZ8T4Z+24ZoF pR85maZfZB6/uv6DeJCIXfKNd1RmWcUzDwIHaHWE+wumy43FeZMnvbMx4+xA8IV/PCwV aYFZCteRIK3jU05X6yK7CIjbHAPYS3/WiaYU6nEK9UuyhIPAF0KyfxGUG0GfgSFSiHxH ppwrEmFtuqCx7UCOVAwjxPLVo7YUsE0RbLUe2ZUL0xXqy2SQvuczK8fyC5WQ0r6XhugY 4jgA== Received: by 10.42.158.71 with SMTP id g7mr2480152icx.38.1333903088590; Sun, 08 Apr 2012 09:38:08 -0700 (PDT) Received: from MacBookPro.local ([117.79.232.249]) by mx.google.com with ESMTPS id wf10sm12135191igb.8.2012.04.08.09.38.03 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 08 Apr 2012 09:38:06 -0700 (PDT) Date: Mon, 9 Apr 2012 00:38:20 +0800 To: "=?utf-8?Q?internals=40lists.php.net?=" Message-ID: <77047AE387984C279CE5250509BB55F1@gmail.com> X-Mailer: sparrow 1.3.2 (build 814.60) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="4f81befc_43d3bcd4_17fca" Subject: [PATCH][Discussion] Ensure property name a valid label and properly handle array2object conversion&Req for bugfix review. From: reeze.xia@gmail.com (reeze) --4f81befc_43d3bcd4_17fca Content-Type: multipart/alternative; boundary="4f81befc_4a10b4e8_17fca" --4f81befc_4a10b4e8_17fca Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi, folks: Recently I have been trying to fix bugs on bugs.php.net. I've been looking at the bug: https://bugs.php.net/bug.php?id=61655. for short: after convert a stdClass with a property with number name to array can't be access anymore. after some code searching, I found that. class property lookup differs from array's. when convert the internal HashTable won't be touched. class property always lookup by string, but array will try to handle numeric(@see Zend/zend_hash.h:307 ZEND_HANDLE_NUMERIC macro). I don't know whether this has been discussed before, if so forgive me please. now PHP allow to access property with this syntax: $obj->{$expr} $expr can be anything. PHP didn't try to validate whether it is a valid label or not. the only problem is we can't access it directly like: $expr = '007gun'; $obj->{$expr} = 10; echo $obj->007gun; It's not a big problem, we can still access it with the same syntax. but after convert to array, we got problem. On the contrary array to object conversion have the same problem: "value", "000invlidlabel" => "2", key" => "value2"); $obj = (object)$ar; $obj->0 will never be accessible, "000invilidlabel" can be access, but can't use normal property access syntax. I know PHP make use of HashTable a lot, maybe because of performance concern or historical reason. but we always want to be better. In my opinion: 1. I see no reason why user will set an invalid label as property name. because It can be access with $obj->{$expr} only or sometime can never been accessed. 2. for the same reason array to object should at least let developer know something they may not want to happen did happened. so I make some change: 1. set a property name should be valid label(__set magic method also follow it) 2. raise warning and move invlid property names to a special property when convert a array contains invlid key name to stdClass. I just want to make things more consist, or maybe we just make sure numeric keys works consist since php is so flexible. Any thoughts? BTW: I sent bugfix for bug#61347 ArrayIterator misrewind and gives misleading notice when manipulating empty/moved to end array https://github.com/php/php-src/pull/38 thanks @nikic & @cataphract's great suggestions, will someone take a look, do I still have to improve it? Thank you! -- reeze | reeze.cn --4f81befc_4a10b4e8_17fca Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
Hi, folks:
Recently I have been trying to fix bugs on bug= s.php.net. I've been looking at the bug: https://bugs.php.net/bug.php=3Fid=3D6= 1655
for short: after convert a stdClass with a prop= erty with number name to array can't be access anymore.

after some code searching, I found that. class property lookup di= ffers from array's. when convert the
internal HashTable won't b= e touched. class property always lookup by string, but array will try to = handle
numeric(=40see Zend/zend=5Fhash.h:307 ZEND=5FHANDLE=5FNU= MERIC macro).

I don't know whether this has been= discussed before, if so forgive me please.

now = PHP allow to access property with this syntax: =24obj->=7B=24expr=7D =24= expr can be anything. PHP
didn't try to validate whether it is = a valid label or not. the only problem is we can't access it directly
like: =24expr =3D '007gun';  =24obj->=7B=24expr=7D =3D 10;= echo =24obj->007gun; It's not a big problem, we can still access
it with the same syntax. but after convert to array, we got problem= .

On the contrary array to object conversion hav= e the same problem:
<=3Fphp
=24ar =3D array(0= =3D> =22value=22, =22000invlidlabel=22 =3D> =222=22, key=22 =3D>= ; =22value2=22);
=24obj =3D (object)=24ar;

=
=24obj->0 will never be accessible, =22000invilidlabel=22 c= an be access, but can't use normal property access syntax.

=

I know PHP make use of HashTable a lot, maybe b= ecause of performance concern or historical reason.
but we alwa= ys want to be better.

In my opinion:
<= span class=3D=22Apple-tab-span=22 style=3D=22white-space:pre=22> 1= . I see no reason why user will set an invalid label as property name. be= cause It can be access with =24obj->=7B=24expr=7D only or sometime can= never been accessed.
2. for the same reason array to object shou= ld at least let developer know something they may not want to happen did = happened.

so I make some change:

<= /div>
1. set a property name should be valid label(=5F=5Fset magic met= hod also follow it)
2. raise warning and move invlid property n= ames to a special property when convert a array contains invlid key name = to stdClass.

I just want to make things more con= sist, or maybe we just make sure numeric keys works consist since ph= p is so flexible.

Any thoughts=3F

=

BTW: I sent bugfix for bug=2361347 ArrayIt= erator misrewind and gives misleading notice when manipulating empty/move= d to end array
https://github.com/php/php-src/pull/38  thanks =40nikic &= amp; =40cataphract's great suggestions, will someone take a look, do I st= ill have to improve it=3F

Thank you=21

-- 
reeze =7C reeze.cn
--4f81befc_4a10b4e8_17fca-- --4f81befc_43d3bcd4_17fca--