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??? Quote 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(); ?> Quote 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... Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.