国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

PHP實現事件機制的方法

2024-04-25 20:38:49
字體:
來源:轉載
供稿:網友

本文實例講述了PHP實現事件機制的方法。分享給大家供大家參考。具體如下:

<?php

/**

* 事件

*/

class Event {

private $callbacks = array();

private $holder;

function __construct() {

$bt = debug_backtrace();

if (count($bt) < 2) {

$this->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) < 2))) {

throw(new Exception('Notify can only be called in holder'));

}

foreach ($this->callbacks as $callback) {

$args = func_get_args();

call_user_func_array($callback, $args);

}

}

}

希望本文所述對大家的php程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鹤峰县| 甘泉县| 东城区| 广宗县| 长宁县| 微山县| 剑河县| 林甸县| 通江县| 德安县| 禹州市| 新沂市| 通榆县| 阿鲁科尔沁旗| 绥化市| 成武县| 沁阳市| 泌阳县| 剑川县| 灌阳县| 万荣县| 罗平县| 和龙市| 台北县| 广丰县| 固原市| 太保市| 固安县| 文登市| 公安县| 西乌珠穆沁旗| 文成县| 穆棱市| 进贤县| 闸北区| 木里| 临汾市| 大方县| 方城县| 克东县| 榕江县|