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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
46 - 41 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 08:01:33 2024 UTC