search

Home  >  Q&A  >  body text

异步 - PHP能否在不更改函数顺序的情况下更改执行顺序?

类似于异步执行的意思吧,如下,能否在不改变各个函数调用顺序的情况下通过改写函数实现one() three()也能输出something

    function one(){
        echo $GLOBALS['obj'];
    }

    function two(){
        $GLOBALS['obj'] = 'something';
    }

    function three(){
        echo $GLOBALS['obj'];
    }

    // Undefined index
    one();

    two();

    // Undefined index
    three();

如果不能,是否有相关的解决方案?

PHP中文网PHP中文网2894 days ago505

reply all(1)I'll reply

  • PHPz

    PHPz2017-04-10 17:36:58

    function one(){
        if(empty($GLOBALS['obj'])){
            two();
        }
    }

    reply
    0
  • Cancelreply