Both method calls and member accesses can be overloaded via the
__call, __get and __set methods. These methods will only be
triggered when your object or inherited object doesn't contain the
member or method you're trying to access.
All overloading methods must be defined as
public.
void __set ( string name, mixed value ) mixed __get ( string name )
Class members can be overloaded to run custom code defined in your class
by defining these specially named methods. The $name
parameter used is the name of the variable that should be set or retrieved.
The __set() method's $value parameter specifies the
value that the object should set the $name.
Example 19-18. overloading with __get and __set example
<?php class Setter { public $n; private $x = array("a" => 1, "b" => 2, "c" => 3);
public function __get($nm) { print "Getting [$nm]\n";
Class methods can be overloaded to run custom code defined in your class
by defining this specially named method. The $name
parameter used is the name as the function name that was requested
to be used. The arguments that were passed in the function will be
defined as an array in the $arguments parameter.
The value returned from the __call() method will be returned to the
caller of the method.
Example 19-19. overloading with __call example
<?php class Caller { private $x = array(1, 2, 3);
public function __call($m, $a) { print "Method $m called:\n"; var_dump($a); return $this->x; } }
Všetky ceny sú s 20% DPH. Konverzny kurz: 1 EUR = 30,1260 SKK
Ceny nezahŕňajú ročný udržiavací poplatok za doménu, ktorý platíme jednotlivým správcom domén.