I am not sure if this possible or if this is the right place to post this type of questions but here goes!
Is there any way to autoload a variable with a class of the same name? An example of this:
class MyClass
{
....
function display() { echo 'test'; }
}
I am wondering if it is possible to do the following:
$MyClass->display();
without previously creating an instance of the MyClass class within the $MyClass variable.
As I say I am not sure if this is possible and if this is not the right place for this kind of question I will happily delete my post.
UPDATE
Thanks for all your responses guys, the more I thought about and after reading your comments I realised it just wasn’t a good idea and really wouldn’t be practical.
Thanks
What you can do is make your method
staticand call the method directly on the class:Apart from that: “Autoloading” variables is not possible.