php - PHP 5.3 Zend - 看不到方法是如何被调用的
问题描述
我遇到了一个我以前没有遇到过的问题。在一个项目的类中(我相信它是基于Zend
框架的),我有一个名为 的方法fetchKey()
,完整的类名是
//found in file Orm.class.php
MyCompany_Core_Orm extends MyCompany_Core_Db (which extends MyCompany_Core)
在 fetchKey 内部,有以下行:
$value = $this->$property;
通过使用 ORM SQL 日志记录(logQueries=1),我可以缩小这一行导致 SQL 查询发生的范围;有了它,查询就会发生,没有它就不会。
$property
是一个字符串,我已经检查过了,该字符串名称没有实际属性。实际上,$property
可以是基于 db 关系的任意数量的值。但关键问题是:老实说,当一个方法仅被引用时,一个未知的函数调用是如何发生的,我真的很困惑。是否存在错误报告或使用__call
或__get
我遗漏的方面?感谢帮助!
作为参考,下面发布了该功能,如果这有助于熟悉:
public function fetchKey($property)
{
//NOTE: I've checked and this logical block doesn't happen
if (self::getOrmProxy() && method_exists(self::getOrmProxy(), __FUNCTION__)) {
$proxyArguments = func_get_args();
return call_user_func_array(array(self::getOrmProxy(), __FUNCTION__), $proxyArguments);
}
$savedPropertyValue = null;
$propertyExists = false;
if (property_exists($this, $property)) {
$propertyExists = true;
$savedPropertyValue = $this->$property;
unset($this->$property);
}
$value = $this->$property;
if ($propertyExists === true) {
$this->$property = $savedPropertyValue;
} else {
unset($this->$property);
}
return $value;
}
解决方案
该函数property_exist()
无法检测使用get()
方法可以神奇访问的属性但是该函数甚至可以找到私有属性。
推荐阅读
- sorting - 使用 grep 的结果对文件进行排序
- javascript - 让用户使用 Javascript 在画布中用鼠标绘制矩形
- laravel - Laravel 中第三级关系的延迟渴望加载
- php - 在数组中获取 php $_GET 值
- angular - 服务变量在子组件中更改时未在父组件中更新
- r - 如何在 R 中堆叠原始变量并创建新变量
- numpy - Numpy 中 x[:] 和 x[...] 的区别
- scala - Scala 中的类型转换
- swift - 当 Userdefaults 中的对象更改时更新 SwiftUI 视图
- android - 带有下拉列表的 Android 工具栏自定义图像视图图标