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
?>
The ReflectionClass class
Introduction
کلاس ReflectionClass اطلاعاتی درباره کلاس ارائه دهد.
Class synopsis
ReflectionClass
implements
Reflector
{
/* Constants */
/* Properties */
public
$name
;
/* Methods */
__construct
( string $argument
)
}Properties
- name
-
Prop description
Predefined Constants
ReflectionClass Node Types
- ReflectionClass::IS_IMPLICIT_ABSTRACT
- ReflectionClass::IS_EXPLICIT_ABSTRACT
- ReflectionClass::IS_FINAL
Table of Contents
- ReflectionClass::__clone — Clone شی
- ReflectionClass::__construct — ساخت ReflectionClass
- ReflectionClass::export — ارسال کلاس
- ReflectionClass::getConstant — دریافت ثابتهای تعریف شده
- ReflectionClass::getConstants — دریافت ثابتها
- ReflectionClass::getConstructor — دریافت سازنده
- ReflectionClass::getDefaultProperties — دریافت خاصیتهای پیشفرض
- ReflectionClass::getDocComment — دریافت توضیحات doc
- ReflectionClass::getEndLine — دریافت خط پایان
- ReflectionClass::getExtension — دریافت اطلاعات ضمیمه
- ReflectionClass::getExtensionName — دریافت نام ضمیمه
- ReflectionClass::getFileName — دریافت filename
- ReflectionClass::getInterfaceNames — دریافت نام واسط
- ReflectionClass::getInterfaces — دریافت واسط
- ReflectionClass::getMethod — دریافت ReflectionMethod
- ReflectionClass::getMethods — دریافت فهرست متدها
- ReflectionClass::getModifiers — دریافت تغییردهنده
- ReflectionClass::getName — دریافت نام کلاس
- ReflectionClass::getNamespaceName — دریافت نام فضای نام
- ReflectionClass::getParentClass — دریافت کلاس والد
- ReflectionClass::getProperties — دریافت خاصیتها
- ReflectionClass::getProperty — دریافت خاصیت
- ReflectionClass::getShortName — دریافت نام کوتاه
- ReflectionClass::getStartLine — گرفتن شماره خط شروع
- ReflectionClass::getStaticProperties — دریافت خاصیتهای استاتیک
- ReflectionClass::getStaticPropertyValue — دریافت مقدار خاصیت استاتیک
- ReflectionClass::hasConstant — بررسی تعریف شدن ثابت
- ReflectionClass::hasMethod — بررسی تعریف شدن متد
- ReflectionClass::hasProperty — بررسی تعریف شدن خاصیت
- ReflectionClass::implementsInterface — پیادهسازی واسط
- ReflectionClass::inNamespace — بررسی بودن در فضای نام
- ReflectionClass::isAbstract — بررسی انتزاعی بودن کلاس
- ReflectionClass::isFinal — بررسی نهایی بودن کلاس
- ReflectionClass::isInstance — بررسی کلاس برای نمونه
- ReflectionClass::isInstantiable — بررسی قابلیت نمونهسازی
- ReflectionClass::isInterface — بررسی واسط بودن
- ReflectionClass::isInternal — بررسی داخلی
- ReflectionClass::isIterateable — بررسی تکرارپذیری
- ReflectionClass::isSubclassOf — بررسی زیرکلاس بودن
- ReflectionClass::isUserDefined — بررسی تعریف شده توسط کاربر
- ReflectionClass::newInstance — نمونه جدید
- ReflectionClass::newInstanceArgs — آرگومانهای نمونه جدید
- ReflectionClass::setStaticPropertyValue — تعیین مقدار خاصیت استاتیک
- ReflectionClass::__toString — به رشته
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 ¶
3 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');
?>
