This problem has driven me nuts in the last two days.... I have a file config.php having a class: class config { public static $Image="/images"; } Another file layout.php is as: require_once("config.php"); class layout { public function writeLogo() { $text = <<<ABC <img class="Logo" title="My Logo" alt="Logo" src="{config::$Image}/Logo.gif" /> ABC; echo($text); } } The problem is that {config::$Image} is evaluating to {config::} Can anyone explain me why & what's the solution???
<? class config { public static $image = "/images" ; } class layout { function __construct( ) { printf( '<img class="Logo" title="My Logo" alt="Logo" src="%s/Logo.gif" />', config::$image ); } } new layout( ); ?> PHP: Curly braces won't work, use (s)printf
Yes, that worked... But the sample function I provided actually outputs a large amount of code. So, I need to concatenate the value of the variable inline. Is that possible??? Moreover, why isn't config::$Image works???
There is no real reason, and nothing wrong with your code, it just so happens that static variables contain syntax that is not interpreted by the Zend engine the same as normal variables are. There is no difference between using sprintf and complementing functions as there is to using curly braces .... $text = 'First text'; $two = 'Second Text'; echo "{$text} then {$two}<br />"; printf("%s then %s<br />", $text, $two ); PHP: are both exactly the same.
Yeah, class static variables are not being parsed inside a heredoc properly... Seems like I have to use workarounds... Thanx