<?php
/**
* Created by PhpStorm.
* User: bee
* Date: 2016/4/24
* Time: 00:17
*/
echo '匿名函数';
$anonymous_func = function(){return 'function';};
echo $anonymous_func();
echo '<br>';
echo '<hr>';
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 '<br>';
$com = new common(1);
echo $com->getVal(2.2).'--';
echo $com->getVal(2.2).'--';
echo (new common(1))->getVal(8.9);
echo '<hr>';echo '匿名类';
//定义匿名类需继承
echo (new class(1) extends common{})->getVal(90);echo '<br>';
echo (new class(2) extends common{})->getVal(90);
<?php
class Outer
{
private $prop = 1;
protected $prop2 = 2;
protected function func1()
{
return 3;
}
public function func2()
{
return new class($this->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
<?php
/**
* Created by PhpStorm.
* User: bee
* Date: 2016/4/24
* Time: 1:51
*/
$arr = array();
for ($i=0; $i<3; $i++){
$arr[] = new class($i){
public $index=0;
function __construct($i)
{
$this->index = $i;
echo 'create</br>';
}
public function getVal(){
echo $this->index;
}
};
}
$arr[2]->getVal();
echo '<br>';
var_dump($arr[1]);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有