|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-06-22 05:53 UTC] 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" />
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 16:00:01 2025 UTC |
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.