(PHP 5)
ReflectionClass 类报告了一个类的有关信息。
$argument
)类的名称。只读,并在尝试赋值的时候会抛出 ReflectionException。
ReflectionClass::IS_IMPLICIT_ABSTRACT
指示了类是一个抽象类(abstract), 因为它有抽象(abstract)方法。
ReflectionClass::IS_EXPLICIT_ABSTRACT
指示了类是一个抽象类(abstract), 因为它已明确定义。
ReflectionClass::IS_FINAL
指示这是一个 final 类。
Anonymous (2013-05-17 06:45:25)
Reflecting an alias will give you a reflection of the resolved class.
<?php
class X {
}
class_alias('X','Y');
class_alias('Y','Z');
$z = new ReflectionClass('Z');
echo $z->getName(); // X
?>
snx (2012-06-19 16:51:32)
if you want to use an object method as a callback parameter for any asynchronous action you have to transfer the reflection method and the object itself.
consider doing something like this:
<?php
class Callback extends ReflectionMethod{
protected $oObject;
public function __construct($oObject, $sMethod){
parent::__construct($oObject, $sMethod);
$this->oObject = $oObject;
$this->setAccessible(true); //to access even protected methods..
}
public function invoke(){
$this->invokeArgs($this->oObject, func_get_args());
}
}
?>
now you can easy create an reflector for the specific object method and pass it to any function...
<?php
class ClassA{
public function doSomething(){
$oCallback = new Callback($this, '_asyncCallback');
doAsyncCall($oCallback);
}
protected function _asyncCallback(...){
//...
}
}
function doAsyncCall($oCallback){
$oCallback->invoke(...);
}
?>
Anonymous (2011-11-11 09:58:16)
Unserialized reflection class cause error.
<?php
/**
* abc
*/
class a{}
$ref = new ReflectionClass('a');
$ref = unserialize(serialize($ref));
var_dump($ref);
var_dump($ref->getDocComment());
// object(ReflectionClass)#2 (1) {
// ["name"]=>
// string(1) "a"
// }
// PHP Fatal error: ReflectionClass::getDocComment(): Internal error: Failed to retrieve the reflection object
?>
thecelavi at gmail dot com (2009-11-30 16:07:39)
Right:
<?php
use AppCore as Core;
$oReflectionClass = new ReflectionClass('App\Core\Singleton');
?>
Wrong:
<?php
use AppCore as Core;
$oReflectionClass = new ReflectionClass('\App\Core\Singleton');
?>
danbettles at yahoo dot co dot uk (2009-03-29 02:48:19)
To reflect on a namespaced class in PHP 5.3, you must always specify the fully qualified name of the class - even if you've aliased the containing namespace using a "use" statement.
So instead of:
<?php
use App\Core as Core;
$oReflectionClass = new ReflectionClass('Core\Singleton');
?>
You would type:
<?php
use App\Core as Core;
$oReflectionClass = new ReflectionClass('App\Core\Singleton');
?>