Here is a code snippet for some of us who are just beginning with reflection. I have a simple class below with two properties and two methods. We will use reflection classes to populate the properties dynamically and then print them:
<?php
class A
{
public $one = '';
public $two = '';
//Constructor
public function __construct()
{
//Constructor
}
//print variable one
public function echoOne()
{
echo $this->one."\n";
}
//print variable two
public function echoTwo()
{
echo $this->two."\n";
}
}
//Instantiate the object
$a = new A();
//Instantiate the reflection object
$reflector = new ReflectionClass('A');
//Now get all the properties from class A in to $properties array
$properties = $reflector->getProperties();
$i =1;
//Now go through the $properties array and populate each property
foreach($properties as $property)
{
//Populating properties
$a->{$property->getName()}=$i;
//Invoking the method to print what was populated
$a->{"echo".ucfirst($property->getName())}()."\n";
$i++;
}
?>
Reflection
- Introduction
- Installing/Configuring
- Predefined Constants
- Examples
- Extending
- Reflection — The Reflection class
- Reflection::export — ارسال
- Reflection::getModifierNames — دریافت نام تغییردهنده
- ReflectionClass — The ReflectionClass class
- 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 — به رشته
- ReflectionExtension — The ReflectionExtension class
- ReflectionExtension::__clone — Clone
- ReflectionExtension::__construct — ساخت ReflectionExtension
- ReflectionExtension::export — ارسال
- ReflectionExtension::getClasses — دریافت کلاس
- ReflectionExtension::getClassNames — دریافت نام کلاس
- ReflectionExtension::getConstants — دریافت ثابتها
- ReflectionExtension::getDependencies — دریافت وابستگیها
- ReflectionExtension::getFunctions — دریافت توابع ضمیمه
- ReflectionExtension::getINIEntries — دریافت ورودی ضمیمه ini
- ReflectionExtension::getName — دریافت نام ضمیمه
- ReflectionExtension::getVersion — دریافت نسخه ضمیمه
- ReflectionExtension::info — دریافت اطلاعات ضمیمه
- ReflectionExtension::__toString — به رشته
- ReflectionFunction — The ReflectionFunction class
- ReflectionFunction::__construct — ساخت شی ReflectionFunction
- ReflectionFunction::export — ارسال تابع
- ReflectionFunction::invoke — احضار تابع
- ReflectionFunction::invokeArgs — احضار آرگومانهای تابع
- ReflectionFunction::isDisabled — بررسی غیرفعال شدن تابع
- ReflectionFunction::__toString — به رشته
- ReflectionFunctionAbstract — کلاس ReflectionFunctionAbstract
- ReflectionFunctionAbstract::__clone — Clone تابع
- ReflectionFunctionAbstract::getDocComment — دریافت توضیح doc
- ReflectionFunctionAbstract::getEndLine — دریافت شماره خط آخر
- ReflectionFunctionAbstract::getExtension — دریافت اطلاعات ضمیمه
- ReflectionFunctionAbstract::getExtensionName — دریافت نام ضمیمه
- ReflectionFunctionAbstract::getFileName — دریافت نام فایل
- ReflectionFunctionAbstract::getName — دریافت نام تابع
- ReflectionFunctionAbstract::getNamespaceName — دریافت نام فضای نام
- ReflectionFunctionAbstract::getNumberOfParameters — دریافت تعداد پارامتر
- ReflectionFunctionAbstract::getNumberOfRequiredParameters — دریافت تعداد پارامترهای مورد نیاز
- ReflectionFunctionAbstract::getParameters — دریافت پارامترها
- ReflectionFunctionAbstract::getShortName — دریافت نام کوتاه تابع
- ReflectionFunctionAbstract::getStartLine — دریافت خط شروع
- ReflectionFunctionAbstract::getStaticVariables — دریافت متغیرهای استاتیک
- ReflectionFunctionAbstract::inNamespace — بررسی قرار داشتن تابع در فضای نام
- ReflectionFunctionAbstract::isClosure — بررسی بستار
- ReflectionFunctionAbstract::isDeprecated — بررسی از رده خارج بودن
- ReflectionFunctionAbstract::isInternal — بررسی داخلی بودن
- ReflectionFunctionAbstract::isUserDefined — بررسی تعریف شدن توسط کاربر
- ReflectionFunctionAbstract::returnsReference — بررسی بازگشت ارجاع
- ReflectionFunctionAbstract::__toString — به رشته
- ReflectionMethod — The ReflectionMethod class
- ReflectionMethod::__construct — ساخت ReflectionMethod
- ReflectionMethod::export — ارسال
- ReflectionMethod::getDeclaringClass — دریافت اعلام کلاس
- ReflectionMethod::getModifiers — دریافت تغییر دهندهها
- ReflectionMethod::getPrototype — دریافت prototype
- ReflectionMethod::invoke — احضار
- ReflectionMethod::invokeArgs — احضار آرگومانها
- ReflectionMethod::isAbstract — بررسی انتزاعی بودن متد
- ReflectionMethod::isConstructor — بررسی سازنده بودن متد
- ReflectionMethod::isDestructor — بررسی نابودگر بودن متد
- ReflectionMethod::isFinal — بررسی نهایی بودن متد
- ReflectionMethod::isPrivate — بررسی خصوصی بودن متد
- ReflectionMethod::isProtected — بررسی حفاظت شده بودن متد
- ReflectionMethod::isPublic — بررسی عمومی بودن متد
- ReflectionMethod::isStatic — بررسی استاتیک بودن متد
- ReflectionMethod::setAccessible — تعیین دسترسی متد
- ReflectionMethod::__toString — به رشته
- ReflectionObject — The ReflectionObject class
- ReflectionObject::__construct — ساخت ReflectionObject
- ReflectionObject::export — ارسال
- ReflectionParameter — کلاس ReflectionParameter
- ReflectionParameter::allowsNull — بررسی مجاز بودن null
- ReflectionParameter::__clone — Clone
- ReflectionParameter::__construct — ساخت
- ReflectionParameter::export — ارسال
- ReflectionParameter::getClass — دریافت کلاس
- ReflectionParameter::getDeclaringClass — دریافت اعلام کلاس
- ReflectionParameter::getDeclaringFunction — دریافت اعلام تابع
- ReflectionParameter::getDefaultValue — دریافت مقدار پیشفرص پارامتر
- ReflectionParameter::getName — دریافت نام پارامتر
- ReflectionParameter::getPosition — دریافت موقعیت پارامتر
- ReflectionParameter::isArray — بررسی نیاز پارامتر به آرایه
- ReflectionParameter::isDefaultValueAvailable — بررسی مقدار پیشفرض موجود
- ReflectionParameter::isOptional — بررسی اختیاری بودن
- ReflectionParameter::isPassedByReference — بررسی ارسال با استفاده از ارجاع
- ReflectionParameter::__toString — به رشته
- ReflectionProperty — کلاس ReflectionProperty
- ReflectionProperty::__clone — Clone
- ReflectionProperty::__construct — ساخت شی ReflectionProperty
- ReflectionProperty::export — ارسال
- ReflectionProperty::getDeclaringClass — دریافت اعلام کلاس
- ReflectionProperty::getDocComment — دریافت توضیح سند
- ReflectionProperty::getModifiers — دریافت تغییردهندهها
- ReflectionProperty::getName — دریافت نام خاصیت
- ReflectionProperty::getValue — دریافت مقدار
- ReflectionProperty::isDefault — بررسی مقدار پیشفرض
- ReflectionProperty::isPrivate — بررسی خصوصی بودن خاصیت
- ReflectionProperty::isProtected — بررسی حفاظت شدن خاصیت
- ReflectionProperty::isPublic — بررسی عمومی بودن خاصیت
- ReflectionProperty::isStatic — بررسی استاتیک بودن خاصیت
- ReflectionProperty::setAccessible — تعیین دسترسی خاصیت
- ReflectionProperty::setValue — تعیین مقدار خاصیت
- ReflectionProperty::__toString — به رشته
- Reflector — واسط Reflector
- Reflector::export — ارسال
- Reflector::__toString — به رشته
Anonymous ¶
2 years ago
