I wanted to wrap an object in another - supporting the structure on heritage but I'm not sure I am there, there is no error.
I have created a square wrapped
thats wrapped by the wrapper
. I have made it so that when a method / property is called on the $ cover
, if it is present in the square, cover
, it will be returned, it will return $ wrapped
object I think differently from the fact that the law / property exists or not, what have I done? Can some explain the code to __ callstatic ()
?
wrapped square {protected $ overlapsprop 1 = 'wrapped: property 1'; Protected $ wrappedProp2 = 'Wrapped: Property 2'; Function method 1 ($ arg1, $ arg2) {echo with the following lines "Called: method 1 ()": $ arg1, $ arg2 "}; static function sMethod2 () {echo 'echo' called a static method ' ;} Function __get ($ name) {return $ this- & gt; $ name;} function __set ($ name, $ val) {$ this-> $ name = $ val;}} square cover {protected $ wrapperProp1 = 'Cover: Property 1'; Protected $ wrapped; Function __ Composition ($ wrapped) {$ this-> Wrapped = $ wrapped;} Function Cover method () {'echo;} function in echo method; __get ($ Name) {if (property_exists ($ this, $ na M)} {$ $ - $ name;} $ this-> wrapped-> $ name;} function __set ($ name, $ val) {if (property_exists ($ this, $ name)) {$ this- & Gt; $ name = $ val;} $ this- & gt; wrapped-> $ name = $ val;} function __call ($ name, $ args = array ()) {call_user_func_array (array ($ this- & gt; ; Wrapped, $ name), $ args;} static work __callStatic ($ name, $ args = array ()) {call_user_func_array (array ('wrapped', $ name), $ args);}} $ wrapper = new wrapper (New wrapped); // Testing Normal Methods $ wrapper- & gt; WrapperMethod (); Cover $ Cover-> RapperProp 1; $ Cover-> RapperProp 1 = 'new wrapper prop 1'; Cover $ Cover-> RapperProp 1; // test representatives $ wrapper-> Method 1 ('Hello', 'World'); // Wrapped :: Method 1 () $ wrapper- & gt; SMethod2 (); // was assigned to static wrapped :: sMethod2 () ... then for the callstas $ echo-> Lipteopop 2 echo; Cover: sMethod2 ();
It seems - it's all right.
About __callStatic () - This allows the undefined constant functions in the class to work. Example:
& lt ;? Php square Foo {static function __callStatic ($ name, $ args = array ()) {resonant "called $ name with temporary work" Print_r ($ Args, true); }} Foo :: Bar ('test'); // output is called "stable function bar" with ultra (0 = & gt; test); "
Comments
Post a Comment