0

I'm new to classes in php and have the following scenario:

whilst working on a larger framework than I'm used to I would like to use a version number for class names stored in a variable declared at the top of a script. Meaning i have tried the following using eval:

<?php 

$Version = '001';

class Foo001{
    public function bar(){
        global $Version;
        echo 'Version = '. $Version;
        //Just so i can see its working
    }



}


class Similar extends eval('Foo'.$Version) {
    public funtion blah(){ 
           // etc... 
    }

}


$Sim = new Similar;

$Sim->bar();
?>

Thought this would be an eval case but obviously it didn't work, cannot find anything on google or a specific post on SO to help.

I have used the {$blah} method for other scenarios and call_user_func etc but have never needed to do this before.

Is this possible or am i just not able to do this?

luk2302
  • 55,258
  • 23
  • 97
  • 137
slappy-x
  • 318
  • 5
  • 13
  • 1
    Why don't you version the class directory (e.g `classes/v1/`)? That way you can just change the directory when you want to upgrade. Developing is also as easy as just using the newest version directory. Creating classes based on a variable, if even possible, is a very dirty way of writing code. – Sverri M. Olsen Jun 05 '15 at 21:40
  • Yep b.enoit.be best post for my scenario. answered my question thanks, it didn't pop up in my search. Thanks sverri probably the best solution, was hoping to avoid creating too many dir's whilst in the first stages of set up & experimenting. – slappy-x Jun 05 '15 at 22:07

0 Answers0