note 117265 added to language.oop5.constants

From: Date: Tue, 12 May 2015 10:44:59 +0000
Subject: note 117265 added to language.oop5.constants
Groups: php.notes 
Request: Send a blank email to php-notes+get-202504@lists.php.net to get a copy of this message
Square or curly bracket syntax can normally be used to access a single byte (character) within a string. For example: $mystring[5]. However, please note that (for some reason) this syntax is not accepted for string class constants (at least, not in PHP 5.5.12). For example, the following code gives "PHP Parse error: syntax error, unexpected '[' in php shell code on line 6". <?php class SomeClass { const SOME_STRING = '0123456790'; public static function ATest() { return self::SOME_STRING[0]; } } ?> It looks like you have to use a variable/class member instead. ---- Server IP: 72.52.91.14 Probable Submitter: 217.46.216.121 ---- Manual Page -- http://php.net/manual/en/language.oop5.constants.php Edit -- https://master.php.net/note/edit/117265 Del: integrated -- https://master.php.net/note/delete/117265/integrated Del: useless -- https://master.php.net/note/delete/117265/useless Del: bad code -- https://master.php.net/note/delete/117265/bad+code Del: spam -- https://master.php.net/note/delete/117265/spam Del: non-english -- https://master.php.net/note/delete/117265/non-english Del: in docs -- https://master.php.net/note/delete/117265/in+docs Del: other reasons-- https://master.php.net/note/delete/117265 Reject -- https://master.php.net/note/reject/117265 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#202504) next »