加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP7匿名类用法分析

发布时间:2020-12-12 21:44:31 所属栏目:PHP教程 来源:网络整理
导读:本篇章节讲解PHP7匿名类用法。供大家参考研究具体如下: ';echo ' ';class common { public $default = 10; function __construct($key){ $this->getVal($key); } public function getVal(int $i):int{ $this->default += $i; return $this->defau

本篇章节讲解PHP7匿名类用法。分享给大家供大家参考,具体如下:

'; echo '
'; class common { public $default = 10; function __construct($key){ $this->getVal($key); } public function getVal(int $i):int{ $this->default += $i; return $this->default+0.1; } } echo '有名函数';echo '
'; $com = new common(1); echo $com->getVal(2.2).'--'; echo $com->getVal(2.2).'--'; echo (new common(1))->getVal(8.9); echo '
';echo '匿名类'; //定义匿名类需继承 echo (new class(1) extends common{})->getVal(90);echo '
'; echo (new class(2) extends common{})->getVal(90);

运行效果图如下:

prop) extends Outer { private $prop3; public function __construct($prop) { $this->prop3 = $prop; } public function func3() { return $this->prop2 + $this->prop3 + $this->func1(); } }; } } echo (new Outer)->func2()->func3();//6

index = $i; echo 'create
'; } public function getVal(){ echo $this->index; } }; } $arr[2]->getVal(); echo '
'; var_dump($arr[1]);

运行效果图如下:

更多关于PHP相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》、《》及《》

希望本文所述对大家PHP程序设计有所帮助。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读