您好,欢迎访问一九零五行业门户网

PHP7匿名类的用法示例(代码)

本篇文章给大家带来的内容是关于php7匿名类的用法示例(代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
<?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();
<?php$fun = function (){ print '这是匿名函数'. php_eol;};$fun();===================================================================================================================class animal{ public $num; public function __construct(...$args) { $this->num = $args[0]; } public function getvalue($su): int { return $this->num + $su; }}$an = new animal(4);echo $an->getvalue(12) . php_eol;echo '匿名类'. php_eol;echo (new class(11) extends animal{})->getvalue(12);
以上就是php7匿名类的用法示例(代码)的详细内容。
其它类似信息

推荐信息