/**
* person class
*/
class Person { /**
* person class -> function say
*/
public static function say($i)
{
echo "hi-->";
var_dump($i);
//return "hi";
} }
class Dog{
public function say()
{
echo "wang !";
}
}

APO的主要思路 (__call魔术方法:调用一个没有的方法时执行)

interface Monitor{
public function __construct($class);
public function __call($name, $arguments);
} abstract class Event{
public abstract function before();
public abstract function after();
} class MonitorBase implements Monitor{
private $classes = null;
public function __construct($class){
$this->classes=$class; }
public function __call($name, $arguments){
echo "前置输出";
echo $name; call_user_func(array($this->classes,$name),$arguments);
echo "后置输出";
}
}

测试 :

$p = new MonitorBase(new Person());
$p->say("888",'666',array(1,2,3,65,4)); $d = new MonitorBase(new Dog());
$d->say();

结果:

最后:细心的读者可能注意到 抽象类Event 没有用到

这个其实可以让 Person 和Dog 继承然后重写 before()和after(),这样每一个类都有自己的前置和后置通知了...

最新文章

  1. FreeRTOS run on eclipse
  2. Linux下python升级至2.7
  3. HDU 3709 Balanced Number
  4. c语言scanf返回值
  5. NPOI 读写Excel
  6. Linux 高可用开源方案 Keepalived VS Heartbeat对比
  7. AJAX如何接收JSON数据
  8. inand和emmc区别
  9. sizeWithFont 不是线程安全。
  10. zoj 3716
  11. hdu 1563 Find your present!
  12. eval & exec(绕过长度限制思路学习)
  13. c#发送get请求
  14. C# ASP.NET 转换为int型的方法 很实用
  15. 【编程技巧】alert vs Ext.Msg.alert
  16. poj-1008-玛雅历
  17. 【转】构建高性能WEB站点之 吞吐率、吞吐量、TPS、性能测试
  18. tkinter学习系列(二)之窗口的设置
  19. Django本地开发,引用静态文件,火狐浏览器不能访问静态文件,谷歌浏览器却能访问静态文件
  20. excel 获取提取数字

热门文章

  1. 查看centos当前版本
  2. [React] Simplify and Convert a Traditional React Form to Formik
  3. linux的子进程调用exec( )系列函数
  4. maven 下载源码
  5. 织梦DeDeCms会员登录或退出跳转到首页的修改方法
  6. Excel中R1C1引用样式
  7. android中的数据库操作(SQLite)
  8. SQL左连接右连接
  9. Linux 小知识点
  10. STS 设置 注解提示