Skip to content
Advertisement

call methods and objects using php

i have this code :

JavaScript

in my code i don’t always want to use

$test = new test ….

I want to use the name directly instead of $test. For example:

JavaScript

Advertisement

Answer

You should use a factory method pattern or something like that. With a factory method you can create a class based on a string. In PHP it’s not that hard. Try something like this:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement