What is PHP artifice?

Source: Internet
Author: User
Tags scalar

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--&gt, 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;
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.