php 理解
2016-03-23 18:46
393 查看
<?php class t { var $num; var $dynamic_function; public function dynamic_function() { $func = $this->dynamic_function; $func($this); } } $p = new t(); $p->num = 5; $p->dynamic_function = function($this_ref) { echo $this_ref->num++.'<br />'; }; $p->dynamic_function(); $p->dynamic_function = function($this_ref) { echo $this_ref->num.'<br />'; $this_ref->num *= 3; }; $p->dynamic_function(); $p->dynamic_function(); $p->dynamic_function(); echo $p->num; /* 5 6 18 54 162 */ ?>
session_start(); $authorise = function($func) { return function() use ($func) { if ($_SESSION['is_authorised'] == true) { $args = func_get_args($func); call_user_func_array($func, $args); } else { echo "Access Denied"; } }; }; $a = function($foo) { echo "Service returns: $foo"; }; $service = $authorise($a); $_SESSION['is_authorised'] = true; $service('123',"2222222"); $_SESSION['is_authorised'] = false; $service('test 2');
相关文章推荐
- file的getPath getAbsolutePath和getCanonicalPath的不同
- 学习Discuz! X3.2记录:一个小提示,可以知道插件php文件语法出问题了
- 中介PHP连接前台HTML与数据库MySQL
- PHP 购物车 php闭包 array_walk
- Scala、PHP、Golang 二分法查找
- yii2实现数据分页显示
- 文件传输导致PHP-smarty白屏故障
- PHP核心技术与最佳实践——总结
- Setting下增加触摸笔功能(TP)
- Thinkphp3.2.3 解决关联模型的自动生成问题($_auto)
- Yii2 表单
- windows环境phpstorm调试环境搭建
- laravel 5.2 form模块调用时出错
- yii2 邮件发送
- PHP并发IO编程之路
- 浅谈PHP类与对象
- 利用Angular.js从PHP读取后台数据
- Ubuntu 14.04 vsftp refusing to run with writable root inside chroot问题解决方法
- PHP 网页保存为Word文档
- PHP输出Excel两种方法