php class member functions defined in the second, dynamic class member function is defined

Scenario:
1. Dynamic load class members (some of swoole framework, modified code need to override the server, you can dynamically load multiple files spread function)
2. Write avoid conflict with the team to develop a document that he alone can be an extension file;
code for a class 3 too much, some of the member functions decomposed into a plurality of files;

<PHP?
class User {
static $ funcs = Array ();
static function EXT (Method $, $ FUNC) {$ :: Self funcs [$ Method] = $ FUNC;}
// call the method does not exist
function __call ( FUNC $, $ args) {
// // able to load a file /extgo/class.func.ext.php class name, function name, the definition of a rule
if (isset (self :: $ funcs [$ func])) {
$ $ classFunc :: = Self funcs [$ FUNC];
return $ classFunc ($ the this);
}
echo "FUNC} {$ method is not really really saved!";
}
/////// ////////////////////////// some other method //////////////////// ///////////////
var $ IDX = 0;
function The gotest () {
$ this-> IDX ++;
echo "user.test: {$ this-> IDX} \ R & lt \ n-" ;
}

}
// Method 1 is a user class extend
user :: EXT ( 'the Add', function ($ pThis) {
echo "Exec the Add \ R & lt \ n-";
$ pthis-> IDX ++;
$ pthis-> The gotest ();
});

// call the user class 2 add method
$ C = new new user ();
$ the C-> add ();

. @ 3 may also be defined again
User :: EXT ( 'the Add', function ($ pThis) {
echo 'Exec ADD2 \ R & lt \ n-';
$ pthis-> = 20 is IDX;
$ pthis-> The gotest ();
} );

. Add method calls the user class 4 //
$ c-> add ();

Guess you like

Origin blog.51cto.com/ewoosoft/2421473