r_honey Posted June 21, 2007 Share Posted June 21, 2007 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??? Link to comment https://forums.phpfreaks.com/topic/56567-problem-with-class-static-variables/ Share on other sites More sharing options...
Barand Posted June 21, 2007 Share Posted June 21, 2007 try this way <?php class config { public static $Image="/images"; } class layout { public function writeLogo() { $dir = config::$Image; $text = <<<ABC <img class="Logo" title="My Logo" alt="Logo" src="$dir/Logo.gif" /> ABC; echo($text); } } $x = new layout; $x->writeLogo(); ?> Link to comment https://forums.phpfreaks.com/topic/56567-problem-with-class-static-variables/#findComment-279416 Share on other sites More sharing options...
r_honey Posted June 22, 2007 Author Share Posted June 22, 2007 Obviously, that works!!! As PHP uses a slightly different syntax & implementation for OOPs, I was searching php.net to see if there was any problem with my syntax... Looks like I have to use the workaround.. Static variables are not being interpreted by the Zend engine the same as normal variables are.. Anyways Thanx... Link to comment https://forums.phpfreaks.com/topic/56567-problem-with-class-static-variables/#findComment-279904 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.