dongzhi2332 2012-03-02 00:35
浏览 43
已采纳

PHP函数调用返回致命错误

For some reason my PHP function call <? r(); ?> returns a fatal error. Any help?

<?php
//$r is previously assigned
function r() {
    echo ( $r );
};
?>

<html>
    <head>
        <link type="text/css" rel="stylesheet" href="<? r(); ?>rs/css/master.css">
    </head>
  • 写回答

2条回答 默认 最新

  • douhao5280 2012-03-02 00:37
    关注

    If you want to refer to a global object from inside an object, you need to explicitly declare it as global:

    function r() {
        global $r;
        echo ( $r );
    }
    

    But in general, referring to global variables in this way is bad style. You should consider passing in prerequisites as function arguments:

    function r($r) {
         echo ( $r );
    }
    
    ...
    
    r($r);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?