【发布时间】:2013-05-31 02:40:21
【问题描述】:
在 PHP 中是否可以在调用类中的函数时触发事件,而不将其添加到类中的每个函数中?
例子:
<?php
class A {
function xxx() {
//this function will be called everytime I call another function in this class
}
public static function b() {
return 'Hello Stackoverflow!';
}
public static function c() {
//I also want this function to trigger the event!
}
}
echo A::b();
?>
【问题讨论】:
-
您实际上想要执行Aspect-oriented Programming。一个通用的 AOP 解决方案对于您当前的目的可能有点(或非常)重量级,但 this article 谈到使用 FLOW 的 AOP 功能。不确定您是只需要一次还是在一百万个地方需要此功能,所以这对您来说可能是多余的。 耸耸肩 编辑:更好的是,@Oswald 对 Go! 的回答!可能是更好的选择框架。