magic methods - PHP implements ArrayAccess -
I have two classes like Foo & amp; Bar
class bar extends foo {public $ element = null; Public function __construct () {}} and goes as class foo
class foo applies ArrayAccess {Private $ data = [ ]; Private $ elementId = null; Public function __call ($ functionName, $ arguments) {if ($ this-> elementId! == faucet) {echo "function $ functionName called with logic" Print_r ($ logic, true); } Back true; } Public function __ composition ($ id = zero) {$ this- & gt; ElementId = $ id; } Public function offsetset ($ offset, $ value) {if (is_null ($ offset)) {$ this- & gt; Data [] = $ value; } And {$ this- & gt; Data [$ offset] = $ value; }} Public Functions OffsetExists {Return Providers ($ -> - Offset [Data Offset]); } Offset Offset of Public Function {if ($ this-> Offset Axis ($ Offset)} {Without Set ($ this-> Data Offset Offset); }} Public Functions Offset Gate ($ Offset) {If (! $ This-> Offset Axis ($ Offset)) {$ this- & gt; $ Offset = new foo ($ offset); }}} I think that when I run the part below the code:
$ a = new bar (); $ A ['says something'] - & gt; Say hello ('hello said!'); The function of FU's __call magic method says that the hello is called hello! .
Here, I have to say that Strong> __ build with $ this-> gtc: elementId and sayHello should be taken as the __ call magic method method and < Strong> Hello said should be taken as the parameter for the Hello function. Also, such series methods are required:
$ a ['say'thing'] -> Say hello ('hello said!') - & gt; Cobbay ('Bye!');
If I'm not mistaken, then you should change foo :: offsetGet Public Function Offset Gate ($ Offset) {If (! $ This-> Offset Accents) {New Self ($ the- & $) Gt;; elementId); } And {return $ this-> Data [offset offset]; This automatically gives an example if there is no element on given offset.
He said, foo :: __ construct () to bar :: __construct () to and Value other than null should be passed: class bar extends foo {public $ element = null; Public function __ composition () {origin: __ creation (42); }} Update To make a chain call, you can send this frequency to __ call () To return: Public function __call ($ functionName, $ arguments) {if ($ this-> elementId! == faucet) {echo "function" $ functionName called with logic Went "Print_r ($ argument, true); } $ This return; }
Comments
Post a Comment