Answer the question
In order to leave comments, you need to log in
Is it possible to automatically call a class in PHP?
Hello!
In procedural programming, it is possible to create a function and call it immediately (even with parameters). Something like:
( function( $a, $b ) {
print $a + $b;
})( 2, 4 );
include_once 'my_class.php';
Answer the question
In order to leave comments, you need to log in
Firstly, this is not called procedural, but functional programming
Secondly, I again very much doubt that this is exactly what you need. In particular, "call a class" is nonsense, methods are called , not the classes themselves
Third, by analogy with functional programming, this is called an anonymous class
(new class {
public function log($msg)
{
echo $msg;
}
})->log("hello");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question