How can I Instatiante objects dynamically in PHP?

clareto

New Member
Messages
250
Reaction score
0
Points
0
I have a question:
Is there any way to reference a class?
For example, I dont want to create an object until I make use of it. So I would like to have something like an ObjectManager that would return me an object when I request it.

the ideal code would be

PHP:
class classA{
 //code here
}

class classB{
 //code here
}

class ObjectManager{
 //methods and fields of ObjectManager
}

$myObjectManager = new ObjectManager();

$myObjectManager->RegisterClass(classA);
$myObjectManager->RegisterClass(classB);

$objectOfClassA = $myObjectManager->GetObject('class A');
$objectOfClassB = $myObjectManager->GetObject('class B');

[[If you got the idea and have a different technique to achieve it, please...]]


By the way, whats the difference of using
new ObjectManager;
and
new ObjectManager();
???
thanks.
 
Last edited:
Top