Class Object (namespace Nette)
Nette\Object is the ultimate ancestor of all instantiable classes.
It defines some handful methods and enhances object core of PHP:
- access to undeclared members throws exceptions
- support for conventional properties with getters and setters
- support for event raising functionality
- ability to add new methods to class (extension methods)
- $val = $obj->label; // equivalent to $val = $obj->getLabel();
- $obj->label = 'Nette'; // equivalent to $obj->setLabel('Nette');
Event functionality is provided by declaration of property named 'on{Something}' Multiple handlers are allowed.
- public $onClick; // declaration in class
- $this->onClick[] = 'callback'; // attaching event handler
- if (!empty($this->onClick)) ... // are there any handlers?
- $this->onClick($sender, $arg); // raises the event with arguments
Adding method to class (i.e. to all instances) works similar to JavaScript prototype property. The syntax for adding a new method is:
- MyClass::extensionMethod('newMethod', function(MyClass $obj, $arg, ...) { ... });
- $obj = new MyClass;
- $obj->newMethod($x);
Direct Known Sub-classes:
| Method Summary | |
|---|---|
| static mixed |
extensionMethod
(string $name, [mixed $callback =
NULL])
Adding method to class.
|
| string |
getClass
()
Returns the name of the class of this object.
|
| ReflectionObject |
Access to reflection.
|
| mixed |
__call
(string $name, array $args)
Call to undefined method.
|
| static mixed |
__callStatic
(string $name, array $args)
Call to undefined static method.
|
| & mixed |
__get
(string $name)
Returns property value. Do not call directly.
|
| bool |
__isset
(string $name)
Is property defined?
|
| void |
__set
(string $name, mixed $value)
Sets value of a property. Do not call directly.
|
| void |
__unset
(string $name)
Access to undeclared property.
|
| Method Details | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
line 171 extensionMethodpublic static mixed extensionMethod (string $name, [mixed $callback = Adding method to class.
|
|||||||||||||||||||||
|
line 81 getClasspublic string getClass () Returns the name of the class of this object.
|
|||||||||||||||||||||
|
line 93 getReflectionpublic ReflectionObject getReflection () Access to reflection.
|
|||||||||||||||||||||
|
line 108 __callpublic mixed __call (string $name, array $args) Call to undefined method. Overridden in child classes as:
|
|||||||||||||||||||||
|
line 156 __callStaticpublic static mixed __callStatic (string $name, array $args) Call to undefined static method.
|
|||||||||||||||||||||
|
line 234 __getpublic mixed & __get (string $name) Returns property value. Do not call directly. Overridden in child classes as:
|
|||||||||||||||||||||
|
line 307 __issetpublic bool __isset (string $name) Is property defined? Overridden in child classes as:
|
|||||||||||||||||||||
|
line 273 __setpublic void __set (string $name, mixed $value) Sets value of a property. Do not call directly. Overridden in child classes as:
|
|||||||||||||||||||||
|
line 322 __unsetpublic void __unset (string $name) Access to undeclared property. Overridden in child classes as:
|
|||||||||||||||||||||