Recently developed a set of their own framework, developed one months, has been uploaded to Git, learned a lot, the series of articles I will slowly write quite a lot
Here first of all the general framework used in some of the functions, I am here to list some of the functions on the Internet, the definition of parameters, and so on, I do not copy, I learn not to move these things, but to record their own understanding and test:
A get_called_class
Who invokes the name of the class that displays the call (including inheritance, etc.), the framework used a lot, in the creation of drivers and so on.
Example:
class Foo { static public function test () { var_dump (Get_called_class ())} } class Bar extends Foo {}foo::test (); bar::test (); Output: string (3"foo"string(3"bar "
Two Func_get_args
Get the real pass parameters, do not ignore, some functions have default values, these are not counted in the Func_get_args, in the framework of the use of a lot. It is mainly used for unknown user typed parameters and multi-variable processing situation.
Create ($name, $type ='PHP') {var_dump (Func_get_args ());} Create ('@'); =="Output Array0=string '@'(length=1)
Create ('@', ' DD '); ==>Array0=string '@'(length=1) 1=string 'DD'(length=2)
Three Call_user_func_array
-Call the callback function and use an array parameter as the parameter of the callback function
<?phpfunction foobar ($arg, $arg 2) {echo __function__,"got $arg and $arg 2\n";}classFoo {function bar ($arg, $arg 2) {echo __method__,"got $arg and $arg 2\n"; }}call_user_func_array ("Foobar", Array (" One"," Both") ); $foo=NewFoo;call_user_func_array (Array ($foo,"Bar"), Array ("three"," Four"));?>the output of the above routines is similar to: Foobar got one and Twofoo::bar got three and four
As you can see, it is possible to callback different methods by loading different array configurations, which can be used for some event listening and triggering
Four Reflectionclass reflex
This is certainly one of the most important parts. In the process of frame scheduling, it is often used to reflect
//class testing and reflection classtestextend{ Publicfunction Sikao () {//Echo ' I am thinking ... '; } } classTest extends testextend{ Publicfunction __construct () {echo"I am construct ...."; } Constconn ='Nihao'; ConstCONN1 ='Nihao'; Public$NL =0; Public$NL 2 =Ten; Publicfunction Addnl () {$ This->NL =Ten; } Publicfunction Say () {echo'I am say ...'; } Publicfunction Sikao () {echo'I am thinking ...'; } }$ref=NewReflectionclass ('Test' ); The class name of the parameter can also be used with the object Var_dump ($ref); GetClass ($a); function GetClass ($className) {echo'<pre>'; $ref=NewReflectionclass ($className); Echo'class name is:'.$ref->getname ().'<br><br>'; //Get Constants$contans = $ref-getconstants (); Echo'The Contans is:'; foreach($contans as$k =$v) {echo $k.' : '. $v.' || '; } Echo'<br>','<br>'; //Get Properties$shuxing= $ref-getProperties (); foreach($shuxing as$k =$v) { foreach($v as$i =$j) { if('name'==$i) {echo' the'. $k.'shuxing is:'. $j.'<br>'; }}} Echo'<br>'; //Get Method$mothods = $ref-GetMethods (); foreach($mothods as$k =$v) { foreach($v as$i =$j) { if('name'==$i) {echo' the'. $k.'methods is:'. $j.'<br>'; } } } }
Five __callstatic && __call
__call the __call method is called automatically when the method to invoke does not exist or has insufficient permissions.
__callstatic the __callstatic method is called automatically when a static method that is called does not exist or has insufficient permissions.
/** * Magic Method * * @param type $name * @param type $arguments * @return type */ Public Staticfunction __callstatic ($name, $arguments)//$name Call the method name, $arguments as the parameter {//$name = Get//Var_dump ($arguments); array//0 = String ' m ' (length=1)//1 = boolean false returnCall_user_func_array ('Self::getall', Array_merge (Array ($name), $arguments)); }
Get started with the MVC Framework (i)