php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #41776 Class static variables not parsed inside heredoc
Submitted: 2007-06-22 05:53 UTC Modified: 2013-07-31 03:47 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: singlarahul21 at gmail dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: master OS: any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: singlarahul21 at gmail dot com
New email:
PHP Version: OS:

 

 [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" />

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-22 06:47 UTC] 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!!!
 [2013-07-31 03:47 UTC] yohgaki@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues -Operating System: Windows +Operating System: any -PHP Version: 5.2.3 +PHP Version: master
 [2013-07-31 03:47 UTC] yohgaki@php.net
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.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat May 03 15:01:28 2025 UTC