Bug #55132 [Bgs]: String access to an expression gives parse error
| From: | andre at webkr dot de | Date: | Mon, 04 Jul 2011 23:29:00 +0000 |
| Subject: | Bug #55132 [Bgs]: String access to an expression gives parse error | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-161586@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=55132&edit=1
ID: 55132
User updated by: andre at webkr dot de
Reported by: andre at webkr dot de
Summary: String access to an expression gives parse error
Status: Bogus
Type: Bug
Package: Scripting Engine problem
Operating System: Windows 7
PHP Version: 5.3.6
Block user comment: N
Private report: N
New Comment:
I double-checked the manual, there it says:
"Characters within strings may be accessed and modified by specifying the zero-based offset of
the desired character after the string using square array brackets, as in $str[42]. [...] Strings
may also be accessed using braces, as in $str{42}, for the same purpose."
The expression ((string)$i) obviously is a string, as confirmed by var_dump():
string(3) "123"
So I don't see which part of the manual you are referring to.
Previous Comments:
------------------------------------------------------------------------
[2011-07-04 19:01:44] felipe@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
The syntax (...){..} is not intended to work.
------------------------------------------------------------------------
[2011-07-04 18:53:24] andre at webkr dot de
Description:
------------
As documented, "accessing variables of other types [...] using [] or {} silently returns
NULL". Because of this it is necessary to cast an integer to string before string access can be
done. However, this results in a parse error.
Test script:
---------------
$i = 123;
echo $i{1}; // -> empty (expected)
echo ((string)$i){1}; // -> parse error
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=55132&edit=1