How to dynamically create an anonymous class that extends an abstract class in PHP?
anonymous-class, dynamically-generated, php
Solution
I know this is an old post, but I'd like to point out that PHP7 has introduced anonymous classes.
It would look something like this:
$my = new class extends Thread
{
public function run()
{
/** ... **/
}
};
$my->start();
Problem
Simply, let me explain by an example. ``` <?php class My extends Thread { public function run() { /** ... **/ } } $my = new My(); var_dump($my->start()); ?> ``` This is from PHP manual. I am wondering if there is a way to do this in more Java-like fashion. For example: ``` <?php $my = new Thread(){ public function run() { /** ... **/ } }; var_dump($my->start()); ?> ```