Answers for "php call class dynamically"

PHP
0

php call class dynamically

class Player {
    public function SayHi() { print("Hi"); }
}
$player = new Player();

call_user_func(array($player, 'SayHi'));
// or
$player->{'SayHi'}();
// or
$method = 'SayHi';
$player->$method();
Posted by: Guest on May-04-2021
0

php call class method dynamically

//  Non static call
call_user_func( array( $obj, 'method' ) );

//  Static calls
call_user_func( array( 'ClassName', 'method' ) );
call_user_func( 'ClassName::method' ); // (As of PHP 5.2.3)
Posted by: Guest on December-09-2020

Code answers related to "php call class dynamically"

Browse Popular Code Answers by Language