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++;
}
?>
Yansıtma
- Giriş
- Yapılandırma/Kurulum
- Öntanımlı Sabitler
- Örnekler
- Yansıtma Sınıflarının Genişletilmesi
- Reflection — Reflection Sınıfı
- Reflection::export — Sınıfı ihraç eder
- Reflection::getModifierNames — Değiştirici isimlerini döndürür
- ReflectionClass — ReflectionClass Sınıfı
- ReflectionClass::__clone — Nesnenin bir kopyasını oluşturur
- ReflectionClass::__construct — Bir ReflectionClass nesnesi oluşturur
- ReflectionClass::export — Bir sınıf ihraç eder
- ReflectionClass::getConstant — Tanımlı sabitleri döndürür
- ReflectionClass::getConstants — Sabitleri döndürür
- ReflectionClass::getConstructor — Kurucuyu döndürür
- ReflectionClass::getDefaultProperties — Öntanımlı özellikleri döndürür
- ReflectionClass::getDocComment — Belgelendirici açıklamaları döndürür
- ReflectionClass::getEndLine — Son satırın numarasını döndürür
- ReflectionClass::getExtension — Eklenti bilgilerini döndürür
- ReflectionClass::getExtensionName — Eklentinin ismini döndürür
- ReflectionClass::getFileName — Bir dosya adı döndürür
- ReflectionClass::getInterfaceNames — Arayüz isimlerini döndürür
- ReflectionClass::getInterfaces — Arayüzleri döndürür
- ReflectionClass::getMethod — Bir yöntemle ilgili bir ReflectionMethod nesnesi döndürür
- ReflectionClass::getMethods — Yöntem listesini döndürür
- ReflectionClass::getModifiers — Değiştiricileri döndürür
- ReflectionClass::getName — Sınıf ismini döndürür
- ReflectionClass::getNamespaceName — İsim alanı ismini döndürür
- ReflectionClass::getParentClass — Ebeveyn sınıfı döndürür
- ReflectionClass::getProperties — Özellikleri döndürür
- ReflectionClass::getProperty — Bir özellik döndürür
- ReflectionClass::getShortName — Kısa adı döndürür
- ReflectionClass::getStartLine — Başlangıç satır numarasını döndürür
- ReflectionClass::getStaticProperties — Duruk özellikleri döndürür
- ReflectionClass::getStaticPropertyValue — Duruk özelliğin değerini döndürür
- ReflectionClass::getTraitAliases — Returns an array of trait aliases
- ReflectionClass::getTraitNames — Returns an array of names of traits used by this class
- ReflectionClass::getTraits — Returns an array of traits used by this class
- ReflectionClass::hasConstant — Sabit tanımlı mı diye bakar
- ReflectionClass::hasMethod — Yöntem tanımlı mı diye bakar
- ReflectionClass::hasProperty — Özellik tanımlı mı diye bakar
- ReflectionClass::implementsInterface — Arayüz gerçeklenmiş mi diye bakar
- ReflectionClass::inNamespace — Sınıf isim alanında mı diye bakar
- ReflectionClass::isAbstract — Sınıf soyut mu diye bakar
- ReflectionClass::isCloneable — Returns whether this class is cloneable
- ReflectionClass::isFinal — Sınıf bir final sınıf mı diye bakar
- ReflectionClass::isInstance — Sınıf bir nesne örneği mi diye bakar
- ReflectionClass::isInstantiable — Sınıf örneklenebilir mi diye bakar
- ReflectionClass::isInterface — Sınıf bir arayüz mü diye bakar
- ReflectionClass::isInternal — Sınıf yerleşik bir sınıf mı diye bakar
- ReflectionClass::isIterateable — Sınıf yinelenebilir mi diye bakar
- ReflectionClass::isSubclassOf — Sınıf bir alt sınıf mı diye bakar
- ReflectionClass::isTrait — Returns whether this is a trait
- ReflectionClass::isUserDefined — Sınıf bir kullanıcı tanımlı sınıf mı diye bakar
- ReflectionClass::newInstance — Yeni örnek
- ReflectionClass::newInstanceArgs — Yeni örnek değiştirgeleri
- ReflectionClass::newInstanceWithoutConstructor — Creates a new class instance without invoking the constructor.
- ReflectionClass::setStaticPropertyValue — Duruk özelliğe değer atar
- ReflectionClass::__toString — Dizgesel tepkiyi görselleştirir
- ReflectionExtension — ReflectionExtension Sınıfı
- ReflectionExtension::__clone — Nesnenin bir kopyasını oluşturur
- ReflectionExtension::__construct — Bir ReflectionExtension nesnesi oluşturur
- ReflectionExtension::export — Sınıfı ihraç eder
- ReflectionExtension::getClasses — Eklentinin sınıflarını döndürür
- ReflectionExtension::getClassNames — Eklentide tanımlı sınıf isimlerini döndürür
- ReflectionExtension::getConstants — Eklentinin sabitlerini döndürür
- ReflectionExtension::getDependencies — Bağımlılıkları döndürür
- ReflectionExtension::getFunctions — Eklenti işlevlerini döndürür
- ReflectionExtension::getINIEntries — Eklentinin ini girdilerini döndürür
- ReflectionExtension::getName — Eklenti ismini döndürür
- ReflectionExtension::getVersion — Eklentinin sürüm bilgisini döndürür
- ReflectionExtension::info — Eklenti bilgilerini döndürür
- ReflectionExtension::isPersistent — Returns whether this extension is persistent
- ReflectionExtension::isTemporary — Returns whether this extension is temporary
- ReflectionExtension::__toString — Dizgesel tepkiyi görselleştirir
- ReflectionFunction — ReflectionFunction Sınıfı
- ReflectionFunction::__construct — Bir ReflectionFunction nesnesi oluşturur
- ReflectionFunction::export — İşlevi ihraç eder
- ReflectionFunction::getClosure — Returns a dynamically created closure for the function
- ReflectionFunction::invoke — İşlevi çağırır
- ReflectionFunction::invokeArgs — İşlev değiştirgelerini çağırır
- ReflectionFunction::isDisabled — İşlevin iptal edilip edilmediğine bakar
- ReflectionFunction::__toString — Dizgesel tepkiyi görselleştirir
- ReflectionFunctionAbstract — ReflectionFunctionAbstract sınıfı
- ReflectionFunctionAbstract::__clone — İşlevi kopyalar
- ReflectionFunctionAbstract::getClosureThis — Returns this pointer bound to closure
- ReflectionFunctionAbstract::getDocComment — Belgelendirici açıklamaları döndürür
- ReflectionFunctionAbstract::getEndLine — Son satır numarasını döndürür
- ReflectionFunctionAbstract::getExtension — Eklenti bilgilerini döndürür
- ReflectionFunctionAbstract::getExtensionName — Eklenti ismini döndürür
- ReflectionFunctionAbstract::getFileName — Dosya ismini döndürür
- ReflectionFunctionAbstract::getName — İşlev ismini döndürür
- ReflectionFunctionAbstract::getNamespaceName — İsim alanı adını döndürür
- ReflectionFunctionAbstract::getNumberOfParameters — Değiştirge sayısını döndürür
- ReflectionFunctionAbstract::getNumberOfRequiredParameters — Zorunlu değiştirge sayısını döndürür
- ReflectionFunctionAbstract::getParameters — Değiştirgeleri döndürür
- ReflectionFunctionAbstract::getShortName — İşlevin kısa ismini döndürür
- ReflectionFunctionAbstract::getStartLine — Başlangıç satır numarasını döndürür
- ReflectionFunctionAbstract::getStaticVariables — Duruk değişkenleri döndürür
- ReflectionFunctionAbstract::inNamespace — İşlev isim alanına ait mi diye bakar
- ReflectionFunctionAbstract::isClosure — Bir anonim işlev mi diye bakar
- ReflectionFunctionAbstract::isDeprecated — Kullanımı önerilmiyor mu diye bakar
- ReflectionFunctionAbstract::isInternal — İşlev yerleşik mi diye bakar
- ReflectionFunctionAbstract::isUserDefined — İşlev kullanıcı tanımlı bir işlev mi diye bakar
- ReflectionFunctionAbstract::returnsReference — İşlev dönüş değeri gönderimli mi diye bakar
- ReflectionFunctionAbstract::__toString — Dizgesel tepkiyi görselleştirir
- ReflectionMethod — ReflectionMethod Sınıfı
- ReflectionMethod::__construct — Yeni bir ReflectionMethod nesnesi oluşturur
- ReflectionMethod::export — Sınıfı ihraç eder
- ReflectionMethod::getClosure — Returns a dynamically created closure for the method
- ReflectionMethod::getDeclaringClass — Bildiren sınıfı döndürür
- ReflectionMethod::getModifiers — Değiştirici sayısını döndürür
- ReflectionMethod::getPrototype — Bildirimi döndürür
- ReflectionMethod::invoke — Yöntemi çağırır
- ReflectionMethod::invokeArgs — Değiştirgeleri çağırır
- ReflectionMethod::isAbstract — Yöntem soyut mu diye bakar
- ReflectionMethod::isConstructor — Yöntem bir kurucu mu diye bakar
- ReflectionMethod::isDestructor — Yöntem bir yıkıcı mı diye bakar
- ReflectionMethod::isFinal — Yöntem final olarak mı bildirilmiş diye bakar
- ReflectionMethod::isPrivate — Yöntem private olarak mı bildirilmiş diye bakar
- ReflectionMethod::isProtected — Yöntem protected olarak mı bildirilmiş diye bakar
- ReflectionMethod::isPublic — Yöntem public olarak mı bildirilmiş diye bakar
- ReflectionMethod::isStatic — Yöntem bir duruk yöntem mi diye bakar
- ReflectionMethod::setAccessible — Set method accessibility
- ReflectionMethod::__toString — Dizgesel tepkiyi görselleştirir
- ReflectionObject — ReflectionObject Sınıfı
- ReflectionObject::__construct — Bir ReflectionObject nesnesi oluşturur
- ReflectionObject::export — Sınıfı ihraç eder
- ReflectionParameter — ReflectionParameter Sınıfı
- ReflectionParameter::allowsNull — NULL değere izin veriliyor mu diye bakar
- ReflectionParameter::canBePassedByValue — Returns whether this parameter can be passed by value
- ReflectionParameter::__clone — Nesneyi kopyalar
- ReflectionParameter::__construct — Bir ReflectionParameter nesnesi oluşturur
- ReflectionParameter::export — Sınıfı ihraç eder
- ReflectionParameter::getClass — Sınıfı döndürür
- ReflectionParameter::getDeclaringClass — Bildiren sınıfı döndürür
- ReflectionParameter::getDeclaringFunction — Bildiren işlevi döndürür
- ReflectionParameter::getDefaultValue — Değiştirgenin öntanımlı değerini döndürür
- ReflectionParameter::getName — Değiştirgenin ismini döndürür
- ReflectionParameter::getPosition — Değiştirgenin konumunu döndürür
- ReflectionParameter::isArray — Değiştirge değeri bir dizi mi olacak diye bakar
- ReflectionParameter::isDefaultValueAvailable — Öntanımlı bir değerin kullanılabilir olup olmadığına bakar
- ReflectionParameter::isOptional — Değiştirge seçimlik mi diye bakar
- ReflectionParameter::isPassedByReference — Değiştirge gönderimli aktarılabilir mi diye bakar
- ReflectionParameter::__toString — Dizgesel tepkiyi görselleştirir
- ReflectionProperty — ReflectionProperty Sınıfı
- ReflectionProperty::__clone — Özelliği kopyalar
- ReflectionProperty::__construct — Bir ReflectionProperty nesnesi oluşturur
- ReflectionProperty::export — Özelliği ihraç eder
- ReflectionProperty::getDeclaringClass — Bildiren sınıfı döndürür
- ReflectionProperty::getDocComment — Bilgilendirici açıklamaları döndürür
- ReflectionProperty::getModifiers — Değiştirici sayısını döndürür
- ReflectionProperty::getName — Özelliğin ismini döndürür
- ReflectionProperty::getValue — Özelliğin değerini döndürür
- ReflectionProperty::isDefault — Öntanımlı değer mi atanmış diye bakar
- ReflectionProperty::isPrivate — Özellik private olarak mı bildirilmiş diye bakar
- ReflectionProperty::isProtected — Özellik protected olarak mı bildirilmiş diye bakar
- ReflectionProperty::isPublic — Özellik public olarak mı bildirilmiş diye bakar
- ReflectionProperty::isStatic — Özellik duruk mu diye bakar
- ReflectionProperty::setAccessible — Özelliği erişilebilir kılar
- ReflectionProperty::setValue — Özelliğe değer atar
- ReflectionProperty::__toString — Dizgesel tepkiyi görselleştirir
- Reflector — Reflector Arayüzü
- Reflector::export — Sınıfı ihraç eder
- Reflector::__toString — Dizgesel tepkiyi görselleştirir
Anonymous
26-Aug-2010 12:19
