php 理解

<?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');

  

上一篇:Spring Boot项目字符集乱码解决方案


下一篇:学习笔记之(console)