Strict Standards: Only variables should be passed by referen_PHP教程

來源:互聯網
上載者:User
本文章來給大家介紹Strict Standards: Only variables should be passed by reference in解決辦法,各位朋友可參考。

php中使用內建的reset函數可以擷取array的第一個元素的值。例如:

代碼如下 複製代碼

$arr = array('one', 'two', 'three');

echo reset($arr);

// 輸出的結果為 one對於下述代碼,如果php開啟了"Strict Standards",將會看到"Strict Standards: Only variables should be passed by reference in"的提示。

代碼如下 複製代碼

$str = 'netingcn.com';

echo reset(explode('.', $str));

為什麼會這樣呢?可以先看看reset函數的定義:

function reset (array &$array) {}從定義中可以看到,reset接受的參數是一個array的引用。而上述代碼中explode傳回值不是任何array的引用,所以在"Strict Standards"下會有上述提示。解決辦法很簡單,只需要把reset(explode('.', $str))分兩步寫即可。第一步先把explode的傳回值賦給一個變數,第二步把這個變數作為reset參數。

出現上面的提示的不只是reset函數,只要參數接受的是對象引用,而傳值直接使用function傳回值都會看到那樣的提示。例如內建的array_pop、shuffle、curent、next、prev、next等等

http://www.bkjia.com/PHPjc/632075.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632075.htmlTechArticle本文章來給大家介紹Strict Standards: Only variables should be passed by reference in解決辦法,各位朋友可參考。 php中使用內建的reset函數可以擷取array的...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.