Jump to content

Recommended Posts

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

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();
?>

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...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.