php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67711 Can't dereference constant strings
Submitted: 2014-07-29 19:34 UTC Modified: 2016-06-14 13:10 UTC
From: chriswarbo at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Strings related
PHP Version: 5.6Git-2014-07-29 (Git) OS: Linux
Private report: No CVE-ID: None
 [2014-07-29 19:34 UTC] chriswarbo at gmail dot com
Description:
------------
Strings can be dereferenced to get sub-strings of length 1, eg. 'hello'[1] === 'e'.

String variables can be dereferenced, eg. ($x = 'hello') && ($x[1] === 'e')

String constants can't be dereferenced, eg. define('MY_CONST', 'hello') && MY_CONST[1].

Test script:
---------------
<?php
define('MY_CONST', 'hello');
var_dump(MY_CONST[1]);


Expected result:
----------------
'string(1) "e"' on stdout

Actual result:
--------------
Parse error: syntax error, unexpected '[' in /home/chris/test2.php on line 5

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-01 17:21 UTC] tyrael@php.net
-Type: Bug +Type: Feature/Change Request
 [2016-06-14 13:10 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2016-06-14 13:10 UTC] cmb@php.net
That is possible as of PHP 5.6.0, see <https://3v4l.org/lWqe0>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC