猿问

什么是PHP嵌套函数?

在JavaScript中,嵌套函数非常有用:闭包,私有方法以及您拥有的东西。


什么是嵌套PHP函数?有人使用它们吗?


这是我做的小调查


<?php

function outer( $msg ) {

    function inner( $msg ) {

        echo 'inner: '.$msg.' ';

    }

    echo 'outer: '.$msg.' ';

    inner( $msg );

}


inner( 'test1' );  // Fatal error:  Call to undefined function inner()

outer( 'test2' );  // outer: test2 inner: test2

inner( 'test3' );  // inner: test3

outer( 'test4' );  // Fatal error:  Cannot redeclare inner()


慕的地10843
浏览 536回答 3
3回答
随时随地看视频慕课网APP
我要回答