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());
?>
Alternatively, you can use PHP7's Anonymous Classes capability as documented at http://php.net/manual/en/migration70.new-features.php#migration70.new-features.anonymous-classes and http://php.net/manual/en/language.oop5.anonymous.php
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With