php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #61507 Incompatibilty when using isset() on a string with a string key as offset
Submitted: 2012-03-26 10:18 UTC Modified: 2012-03-31 09:48 UTC
From: joffery at ne2000 dot nl Assigned: yohgaki (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.4.0 OS: ANY
Private report: No CVE-ID: None
 [2012-03-26 10:18 UTC] joffery at ne2000 dot nl
Description:
------------
Incompatibility when using isset() on a string with a string key as offset.

Probably an effect of the change "Simplified string offset reading. $str[1][0] is now a legal construct.".

Current implementation seems correct although this is an incompatibility in previous versions and should be documented.

A previous bug (#37727) noted that behavior before 5.4 was incorrect but was filed as 'not a bug'.



Test script:
---------------
$ php -r '$str = "str"; var_dump(isset($str["x"]));'


Expected result:
----------------
bool(false)

Actual result:
--------------
PHP 5.3.9:
bool(true)

PHP 5.4.0:
bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-26 16:37 UTC] yohgaki@php.net
It does. This should be addressed.
 [2012-03-26 16:37 UTC] yohgaki@php.net
-Status: Open +Status: Verified
 [2012-03-31 02:08 UTC] yohgaki@php.net
Changed bug type from "Doc" to "Bug".
Changed Package from "string related" to "scripting engine problem".

I think this should be fixed before 5.4.1.
 [2012-03-31 02:08 UTC] yohgaki@php.net
-Type: Documentation Problem +Type: Bug -Package: Strings related +Package: Scripting Engine problem -Operating System: Linux +Operating System: ANY -Assigned To: +Assigned To: dmitry
 [2012-03-31 02:55 UTC] yohgaki@php.net
Someone who remember the conclusion of var_dump(isset($str["x"]["x"]) could write 
comment?

I'm not sure how $str['x'] is treated now.

If it's doc problem, I'll fix the doc.
 [2012-03-31 07:22 UTC] stas@php.net
-Status: Verified +Status: Not a bug -Package: Scripting Engine problem +Package: Documentation problem
 [2012-03-31 07:22 UTC] stas@php.net
String offset must be a number.
 [2012-03-31 08:02 UTC] yohgaki@php.net
-Type: Bug +Type: Documentation Problem -Assigned To: dmitry +Assigned To: yohgaki
 [2012-03-31 08:03 UTC] yohgaki@php.net
-Status: Not a bug +Status: Open
 [2012-03-31 09:48 UTC] yohgaki@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2012-03-31 09:48 UTC] yohgaki@php.net
-Status: Assigned +Status: Closed
 [2012-08-11 01:03 UTC] mkwan at corp dot oodle dot com
Is the implication that using a string key offset is undefined behavior, so it 
doesn't matter what PHP does?  Because, if the _defined_ behavior is to return 
false, then it is inconsistent with other contexts.

$ php -r '$str = "str"; var_dump(isset($str["x"]));'
bool(false)
$ php -r '$str = "str"; var_dump($str["x"]);'
string(1) "s"

How can something not be set but also have a value?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 11:01:37 2024 UTC