|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-02-12 13:26 UTC] d4n at digitalanalogue dot org
Description:
------------
Can you update the strings document to explain why you cannot use self::$var in any string, or if you can what php version it works in.
I do not know if this is a bug, or if it is my php version, but I can't understand why I can access the var and echo it out yet when I put it in a string using escaped methods it is ignored and throws a notice saying undefined when it clearly is!
Thanks
Dan
Reproduce code:
---------------
class user {
private static $table = "foo";
public function user() {
//blah...
}
public static function test() {
$str = "table = ". self::$table . "<br/>";
echo $str;
// Outputs: table = foo
$str = "table = {self::$table} <br/>";
echo $str;
// Outputs:
// Notice: Undefined variable: table in /*** on line ***
$str = '{self::$table}' . "<br/>";
echo $str;
// Outputs: table = {self::}
$str = <<<EOD
table = self::$table
EOD;
/*
Outputs:
Notice: Undefined variable: table in /*** on line ***
table = self::
*/
echo $str;
}
}
Expected result:
----------------
table = foo
table = foo
table = {self::$table}
table = foo
Actual result:
--------------
table = foo
Notice: Undefined variable: table in /*** on line ***
table = {self::}
table = {self::$table} // correct!
Notice: Undefined variable: table in /*** on line ***
table = self::
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 11:00:01 2025 UTC |
If I remember correctly, the parser only looks for {$ to do variable interpolation, which means you can't use things like constants or static properties.