0

I have two classes, one of them is a configuration class. Inside of this class I have a variable called "theme". This is called config::theme . I have another class, but I can't be sure on the name as It's theme dependant. For instance, if the PHP sites theme is set to "nebula", I need to access the nebula theme, e.g: nebula::navigation . The farthest I've gotten is:

public static function nav( ) {
    $temp = config::theme;

    return eval( $temp . "::navigation" );
}

which outputs the error:

Parse error: syntax error, unexpected $end in C:\Dropbox\Colzdragon\Colzdragon\Site\internal\theme.php(54) : eval()'d code on line 1

Is there any way to do this? Thanks!

3 Answers3

3

You can do this using PHP 5.3. See the first example on this manual page:

public static function nav() {
    $theme = config::$theme;
    return $theme::$navigation;
}
Sander Marechal
  • 22,978
  • 13
  • 65
  • 96
0

Your code works fine (as far as I can tell) PHP is telling you that you missed a }, a ; or a quote somewhere.

Literally it says: "I've read until the end of the file but there is unfinished syntactical business"

0

@Sander's answer works if you have access to PHP 5.3. If you're stuck using an older version (since a lot of cheap hosts don't seem to have 5.3 yet), you can use constant() for this:

constant(get_class($temp)."::navigation");
Community
  • 1
  • 1
AgentConundrum
  • 20,288
  • 6
  • 64
  • 99