On Friday, November 25, 2011 08:23 AM, de...@lucato.it wrote:
On 24 November 2011 21:48, Rasmus Lerdorf<ras...@lerdorf.com>  wrote:
On 11/24/2011 01:44 PM, Yasuo Ohgaki wrote:
Hi all,

I should think twice before seding mail. "abc" as array index is
converted to 0 since it's not a integer. So with current code is
behave consistently with regards to string to long conversion.

However,

PHP 5.3
php -r '$s = "abc"; var_dump($s[0]["bar"]);'
PHP Fatal error:  Cannot use string offset as an array in Command line
code on line 1

PHP 5.4
./php -r '$s = "abc"; var_dump($s[0]["bar"]);'
string(1) "a"

Isn't it better to raise notice for accessing string by string index?
There is no use to allowing string index access to strings. I think
raising notice is feasible. Isn't it?
String index access is still required since they are often numeric
strings. We could add a notice for non-numeric strings, but the check
would slow things down a bit.

-Rasmus


Would it be possible to have that check only if E_NOTICE is enabled ?
That would allow to limit the cost to development environments
(assuming one could disable E_NOTICEs on production env).

Devis
This is a design issue of using the same syntax for arrays and strings, and accepting string indexes for both, I think this is beginning to illustrate some of the flaws in that design.

if (isset($_POST['query']['search'])) { << This does not do what you think (if ?query=a_string..

Although the chained string offset fix is probably the right thing to do, I think it should be reverted in this version, then this process occur:

5.4
- revert chained string offsets
- add E_NOTICE to any usage of string index's of string eg . $a = "string" ; $a["string"] = gives E_NOTICE - users can add (int) if they really need to check string indexes of a string
- isset($string['x']) will return true as present
- isset($string['x']['x']) will return false as present

5.5
 - reapply chained string offsets
- add E_FATAL to any usage of string index's of string = eg . $a = "string" ; $a["string"] = gives E_FATAL ???? - make $a["string"] return an empty string - so isset() on chained string offsets will work as expected. - isset($string['x']) will return false as per the warning on the previous version..
 - isset($string['x']['x']) will return false as present

Thoughts.........

Regards
Alan


















--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to