#47369 [Opn->Csd]: use of {self::$} in a string always triggers Notice: Undefined variable:
| From: | torben@php.net | Date: | Sat, 05 Sep 2009 06:39:25 +0000 |
| Subject: | #47369 [Opn->Csd]: 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-2730@lists.php.net to get a copy of this message | ||
ID: 47369
Updated by: torben@php.net
Reported By: d4n at digitalanalogue dot org
-Status: Open
+Status: Closed
Bug Type: Documentation problem
Operating System: CentOS 5
PHP Version: Irrelevant
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
Previous Comments:
------------------------------------------------------------------------
[2009-09-05 06:39:02] svn@php.net
Automatic comment from SVN on behalf of torben
Revision: http://svn.php.net/viewvc/?view=revision&revision=288077
Log: Noted that the values of static class variables and class
constants
may be accessed as the names of variables in the local scope, but that
single-curly-brace syntax will not work with function or method calls
or static class variables or class constants.
Addresses bug #47369.
------------------------------------------------------------------------
[2009-02-16 15:17:08] smlerman at gmail dot com
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.
------------------------------------------------------------------------
[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