php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55132 String access to an expression gives parse error
Submitted: 2011-07-04 18:53 UTC Modified: 2011-07-04 19:29 UTC
From: andre at webkr dot de Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.6 OS: Windows 7
Private report: No CVE-ID: None
 [2011-07-04 18:53 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-04 19:01 UTC] felipe@php.net
-Status: Open +Status: Bogus
 [2011-07-04 19:01 UTC] 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 19:29 UTC] andre at webkr dot de
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.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 01:01:28 2025 UTC