Home >php教程 >php手册 >PHP实现事件机制的方法

PHP实现事件机制的方法

WBOY
WBOYOriginal
2016-06-06 19:51:401155browse

这篇文章主要介绍了PHP实现事件机制的方法,实例分析了php针对事件机制的定义与实现技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了PHP实现事件机制的方法。分享给大家供大家参考。具体如下:

holder = null; return; } $this->holder = &$bt[1]['object']; } function attach() { $args = func_get_args(); switch (count($args)) { case 1: if (is_callable($args[0])) { $this->callbacks[]= $args[0]; return; } break; case 2: if (is_object($args[0]) && is_string($args[1])) { $this->callbacks[]= array(&$args[0], $args[1]); } return; default: return; } } function notify() { $bt = debug_backtrace(); if ($this->holder && ((count($bt) >= 2 && $bt[count($bt) - 1]['object'] !== $this->holder) || (count($bt) callbacks as $callback) { $args = func_get_args(); call_user_func_array($callback, $args); } } }

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn