xp-framework / core

The XP Framework is an all-purpose, object oriented PHP framework.
Other
19 stars 6 forks source link

Add support for virtual properties #275

Closed thekid closed 3 years ago

thekid commented 3 years ago

The following declares a virtual property named "fullName" on the person class:

/** @property string $fullName */
class Person {

  // ...shortened for brevity, will use __set() and __get()
}

$c= new XPClass(Person::class);

$fields= $c->getFields();          // Includes fullName virtual field
$exists= $c->hasField('fullName'); // true
$field= $c->getField('fullName');  // lang.reflect.Field
$value= $field->get(new Person()); // Invokes Person::__get('fullName')

See xp-framework/rfc#340. Prerequisite for xp-framework/compiler#124 and xp-framework/reflection#14

thekid commented 3 years ago

Released in https://github.com/xp-framework/core/releases/tag/v10.13.0