#47369 [Com]: use of {self::$} in a string always triggers Notice: Undefined variable:
| From: | smlerman at gmail dot com | Date: | Mon, 16 Feb 2009 15:17:08 +0000 |
| Subject: | #47369 [Com]: use of {self::$} in a string always triggers Notice: Undefined variable: | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-1878@lists.php.net to get a copy of this message | ||
ID: 47369
Comment by: smlerman at gmail dot com
Reported By: d4n at digitalanalogue dot org
Status: Open
Bug Type: Documentation problem
Operating System: CentOS 5
PHP Version: Irrelevant
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2009-02-12 13:26:42] 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::
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47369&edit=1