|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 07 18:00:01 2025 UTC |
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.