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
?>
ReflectionClass クラス
(PHP 5)
導入
ReflectionClass クラスは クラスについての情報を報告します。
クラス概要
ReflectionClass
implements
Reflector
{
/* 定数 */
/* プロパティ */
public
$name
;
/* メソッド */
__construct
( mixed
}$argument
)プロパティ
- name
-
クラス名。読み込み専用で、書き込もうとすると ReflectionException をスローします。
目次
- ReflectionClass::__construct — ReflectionClass を作成する
- ReflectionClass::export — クラスをエクスポートする
- ReflectionClass::getConstant — 定義されている定数を取得する
- ReflectionClass::getConstants — 定数を取得する
- ReflectionClass::getConstructor — クラスのコンストラクタを取得する
- ReflectionClass::getDefaultProperties — デフォルトプロパティを取得する
- ReflectionClass::getDocComment — ドキュメントコメントを取得する
- ReflectionClass::getEndLine — 終了行を取得する
- ReflectionClass::getExtension — クラスを定義する拡張モジュールを表す ReflectionExtension オブジェクトを取得する
- ReflectionClass::getExtensionName — クラスを定義する拡張モジュールの名前を取得する
- ReflectionClass::getFileName — クラスが定義されているファイルのファイル名を取得する
- ReflectionClass::getInterfaceNames — インターフェイスの名前を取得する
- ReflectionClass::getInterfaces — インターフェイスを取得する
- ReflectionClass::getMethod — クラスメソッドの ReflectionMethod を取得する
- ReflectionClass::getMethods — メソッドの配列を取得する
- ReflectionClass::getModifiers — 修飾子を取得する
- ReflectionClass::getName — クラスの名前を取得する
- ReflectionClass::getNamespaceName — 名前空間の名前を取得する
- ReflectionClass::getParentClass — 親クラスを取得する
- ReflectionClass::getProperties — プロパティを取得する
- ReflectionClass::getProperty — クラスのプロパティを表す ReflectionProperty を取得する
- ReflectionClass::getShortName — 短い名前を取得する
- ReflectionClass::getStartLine — 開始行を取得する
- ReflectionClass::getStaticProperties — 静的なプロパティを取得する
- ReflectionClass::getStaticPropertyValue — 静的なプロパティの値を取得する
- ReflectionClass::getTraitAliases — トレイトのエイリアスの配列を返す
- ReflectionClass::getTraitNames — このクラスが使うトレイトの名前の配列を返す
- ReflectionClass::getTraits — このクラスが使うトレイトの配列を返す
- ReflectionClass::hasConstant — 定数が定義されているかどうかを調べる
- ReflectionClass::hasMethod — メソッドが定義されているかどうかを調べる
- ReflectionClass::hasProperty — プロパティが定義されているかどうかを調べる
- ReflectionClass::implementsInterface — インターフェイスの実装を調べる
- ReflectionClass::inNamespace — 名前空間内にあるかどうかを調べる
- ReflectionClass::isAbstract — 抽象クラスであるかどうかを調べる
- ReflectionClass::isCloneable — このクラスがクローン可能かどうかを返す
- ReflectionClass::isFinal — final クラスであるかどうかを調べる
- ReflectionClass::isInstance — クラスのインスタンスであるかどうかを調べる
- ReflectionClass::isInstantiable — クラスのインスタンス化が可能であるかどうかを調べる
- ReflectionClass::isInterface — このクラスがインターフェイスであるかどうかを調べる
- ReflectionClass::isInternal — 拡張モジュールあるいはコアで定義された内部クラスであるかどうかを調べる
- ReflectionClass::isIterateable — 反復処理が可能であるかどうかを調べる
- ReflectionClass::isSubclassOf — サブクラスであるかどうかを調べる
- ReflectionClass::isTrait — トレイトであるかどうかを返す
- ReflectionClass::isUserDefined — ユーザー定義であるかどうかを調べる
- ReflectionClass::newInstance — 指定した引数でクラスの新しいインスタンスを作成する
- ReflectionClass::newInstanceArgs — 指定した引数でクラスの新しいインスタンスを作成する
- ReflectionClass::newInstanceWithoutConstructor — コンストラクタを起動せずに新しいクラスのインスタンスを作成する
- ReflectionClass::setStaticPropertyValue — 静的なプロパティの値を設定する
- ReflectionClass::__toString — ReflectionClass オブジェクトの文字列表現を返す
Anonymous ¶
1 year ago
danbettles at yahoo dot co dot uk ¶
4 years ago
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');
?>
Anonymous ¶
7 days ago
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 ¶
11 months ago
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(...);
}
?>
thecelavi at gmail dot com ¶
3 years ago
Right:
<?php
use AppCore as Core;
$oReflectionClass = new ReflectionClass('App\Core\Singleton');
?>
Wrong:
<?php
use AppCore as Core;
$oReflectionClass = new ReflectionClass('\App\Core\Singleton');
?>
