Well let just say that we have a classname called HelloWorld into a file.
File class.HelloWorld.php
class HelloWorld {
function __construct()
{
}
public function doSomething(){
echo "new HelloWorld()->doSomething() was called";
}
public function anotherMethod(){
echo "new HelloWorld()->anotherMethod() was called";
}
}
Now you can instantiate the class on runtime without saving it into a variable.
require('class.HelloWorld.php');
// you can just instantiate it and the constructur will be called automatically
(new HelloWorld());
// or you can instantiate it and call other methods
(new HelloWorld())->doSomething();
I'm not sure if the garbage collector will delete the instantiated classes or not, but i assume since those classes are not saved into a variable this would not be saved somewhere in the memory and that would be perfect.