Reply content:
Since the PHP play closed, everyone jump five floor, not laborious.
1. Foundation:
A sentence implementation defines a function and immediately invokes
We often do that in JavaScript because variable pollution is an intolerable thing. But how does this function in PHP? One possible approach is to:
call_user_func(function(){ echo "hello,world";});
@ Chen, there is a solution to the ha.
class A{ protected function Pro() { return "Pro"; } Public function Pub() { return "Pub"; }}$a = New A();$ext = function () { Var_dump($this); //Var_dump ($this->pro ());//error:call to protected method A::p ro () Var_dump($this -Pub());};$ext = $ext -BindTo($a);Var_dump($ext());
$b=3;switch(1){ case $b==3: echo "fuck"; break;}?>
function Callback($callback) { $callback(); } $obj = (Object) "PHP aaa"; $callback = function () Use ($obj) { Print "This is a closure with object, MSG is:{$obj -scalar}.
"; }; $obj -scalar = "php bbb"; //$obj = (object) "PHP bbb"; Callback($callback);
C language has a tendency to operator-->, and this PHP also has, did not say.
Add one: In the PHP source code can be directly input URL, no need to comment (black magic):
http://www.zhihu.com?>
Artifice this How to say, play also can, but do not use in actual projects, contribute two bar:
Swap two values:
List ($b, $a) = Array ($a, $b);
$a = Array ($b, $b = $a) [0]; Of course, the Magic BOM head, do not know how many PHP beginners sleep well Quora list
What is some cool PHP tricks?
XML string to Array
$xmlObj = simplexml_load_string($xmlStr);$xmlArr = json_decode(json_encode($xmlObj) , true);
1. StdClass ();
$obj = new stdClass;$obj->a = 1;$obj->b = 2;