PHP鐨勫彲鍙樺嚱鏁

鍐呭鎽樿
PHP 鏀寔鍙彉鍑芥暟鐨勬蹇点傝繖鎰忓懗鐫濡傛灉涓涓彉閲忓悕鍚庢湁鍦嗘嫭鍙凤紝PHP 灏嗗鎵句笌鍙橀噺鐨勫煎悓鍚嶇殑鍑芥暟锛屽苟涓斿皾璇曟墽琛屽畠銆傚彲鍙樺嚱鏁板彲浠ョ敤鏉ュ疄鐜板寘鎷洖璋冨嚱鏁帮紝鍑芥暟琛ㄥ湪鍐呯殑涓浜涚敤閫斻
鏂囩珷姝f枃
鍙彉鍑芥暟
PHP 鏀寔鍙彉鍑芥暟鐨勬蹇点傝繖鎰忓懗鐫濡傛灉涓涓彉閲忓悕鍚庢湁鍦嗘嫭鍙凤紝PHP 灏嗗鎵句笌鍙橀噺鐨勫煎悓鍚嶇殑鍑芥暟锛屽苟涓斿皾璇曟墽琛屽畠銆傚彲鍙樺嚱鏁板彲浠ョ敤鏉ュ疄鐜板寘鎷洖璋冨嚱鏁帮紝鍑芥暟琛ㄥ湪鍐呯殑涓浜涚敤閫斻

鍙橀噺鍑芥暟涓嶈兘鐢ㄤ簬璇█缁撴瀯锛屼緥濡 echo()锛宲rint()锛寀nset()锛宨sset()锛宔mpty()锛宨nclude()锛宺equire() 浠ュ強绫讳技鐨勮鍙ャ傞渶瑕佷娇鐢ㄨ嚜宸辩殑鍖呰鍑芥暟鏉ュ皢杩欎簺缁撴瀯鐢ㄤ綔鍙橀噺鍑芥暟銆


Example #1 鍙彉鍑芥暟绀轰緥

<?php
function foo() {
    echo "In foo()<br /> ";
}

function bar($arg = '') {
    echo "In bar(); argument was '$arg'.<br /> ";
}

// 浣跨敤 echo 鐨勫寘瑁呭嚱鏁
function echoit($string)
{
    echo $string;
}

$func = 'foo';
$func();        // This calls foo()

$func = 'bar';
$func('test');  // This calls bar()

$func = 'echoit';
$func('test');  // This calls echoit()
?>
杩樺彲浠ュ埄鐢ㄥ彲鍙樺嚱鏁扮殑鐗规ф潵璋冪敤涓涓璞$殑鏂规硶銆

Example #2 鍙彉鏂规硶鑼冧緥

<?php
class Foo
{
    function Variable()
    {
        $name = 'Bar';
        $this->$name(); // This calls the Bar() method
    }

    function Bar()
    {
        echo "This is Bar";
    }
}

$foo = new Foo();
$funcname = "Variable";
$foo->$funcname();   // This calls $foo->Variable()

?>
璇峰弬闃 call_user_func()锛屽彲鍙樺彉閲忓拰 function_exists()銆

浠ヤ笂灏辨槸PHP鐨勫彲鍙樺嚱鏁扮殑璇︾粏鍐呭锛屾洿澶氫俊鎭鍏虫敞OD浜戝叾瀹冪浉鍏虫枃绔狅紒



鏈枃URL锛http://www.odweb.cn/news_show.html?id=92