Home >Backend Development >PHP Tutorial >Usage example of PHP7 anonymous class (code)
The content of this article is about the usage examples (code) of PHP7 anonymous classes. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
<?php /** * Created by PhpStorm. * User: Itboot * Date: 2019/1/17 * Time: 18:15 */ class An { private $num; protected $age = 15; public function __construct() { $this->num = 1; } protected function bar(): int { return 10; } public function drive() { return new class($this->num) extends An{ protected $id; public function __construct($num) { $this->id = $num; } public function ea() { return $this->id + $this->age + $this->bar(); } }; } } echo (new An())->drive()->ea();rrree
The above is the detailed content of Usage example of PHP7 anonymous class (code). For more information, please follow other related articles on the PHP Chinese website!