Req #41776 [Opn->Wfx]: Class static variables not parsed inside heredoc
| From: | yohgaki@php.net | Date: | Wed, 31 Jul 2013 03:47:12 +0000 |
| Subject: | Req #41776 [Opn->Wfx]: Class static variables not parsed inside heredoc | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-180604@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=41776&edit=1
ID: 41776
Updated by: yohgaki@php.net
Reported by: singlarahul21 at gmail dot com
Summary: Class static variables not parsed inside heredoc
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
-Operating System: Windows
+Operating System: any
-PHP Version: 5.2.3
+PHP Version: master
Block user comment: N
Private report: N
New Comment:
This is because {} is supposed to be used like
{$var} or ${var}
i.e. {$ is parsed as var. To escape "{$" use \ before $. "{\$"
http://php.net/manual/en/language.types.string.php
{config::$Image} will not be parsed as variable. Just like
// Won't work, outputs: This is the return value of getName(): {getName()}
echo "This is the return value of getName(): {getName()}";
Supporting this will introduce confusion. IMO.
Previous Comments:
------------------------------------------------------------------------
[2007-06-22 06:47:16] singlarahul21 at gmail dot com
Update: It seems like class static variables are not parsed inside any quoted string. And because
heredoc is practically a quoted string, they are not parsed inside heredoc too!!!
------------------------------------------------------------------------
[2007-06-22 05:53:24] singlarahul21 at gmail dot com
Description:
------------
A class static variable is not recognized & parsed inside heredoc. Instead the class name &
scope resolution operator is passed in the string variable & the static variable name is tried
to be parsed as a Independent local variable.
Reproduce code:
---------------
<?php
class config
{
public static $Image="/images";
}
class layout
{
public function writeLogo()
{
$text = <<<ABC
<img class="Logo" title="My Logo" alt="Logo"
src="{config::$Image}/Logo.gif" />
ABC;
echo($text);
}
}
$sample = new layout();
$sample->writeLogo();
?>
Expected result:
----------------
I expect the following tag to be outputted:
<img class="Logo" title="My Logo" alt="Logo"
src="/images/Logo.gif" />
Actual result:
--------------
<img class="Logo" title="My Logo" alt="Logo"
src="config::/Logo.gif" />
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=41776&edit=1