xiaozi 2015-01-10 20:35:29
php < 5.3.2中没有提供ReflectionMethod::setAccessible,那怎么获取私有属性呢?@qiyuuu
function getPrivatePropertyOfObj($obj, $name) {
$arr = (array)$obj;
$key = "\0" . get_class($obj) . "\0" . $name;
return isset($arr[$key]) ? $arr[$key] : null;
}
function getProtectedPropertyOfObj($obj, $name) {
$arr = (array)$obj;
$key = "\0*\0" . $name;
return isset($arr[$key]) ? $arr[$key] : null;
}