php 函數參數的引用

<?php
error_reporting(E_ALL);
sweep ($ignore, $ignore);
// no errors occur here

sweep($a=1,$b=1);

/**
	程序設計處理,	
	1  在使用了引用的參數,傳遞一個爲null的參數, 在函數內部若是從新給參數賦值, 則之內部賦值結果爲準
	2  若是參數被定義爲引用, 在函數內部若是有從新賦值, 則在此程序後, 被使用的參數,都會永久變動爲函數內賦值的新值.
    3  在開啓了捕獲全部錯誤信息的開關後, 若是對引用參數,傳遞了臨時變量, 則會出現錯誤.

**/
function sweep ( &$filecount, &$bytecount ) {
  var_dump($filecount,$bytecount);
  $filecount = 1;
  $bytecount = 1024;
  print "Files: $filecount - Size: $bytecount"; 
  // prints "Files: 1024 - Size: 1024"
}


// output


---------- php ----------
NULL
NULL
Files: 1024 - Size: 1024
Strict Standards: Only variables should be passed by reference in D:\phpStudy\WWW\demo\fun_argc_refresh.php on line 6

Strict Standards: Only variables should be passed by reference in D:\phpStudy\WWW\demo\fun_argc_refresh.php on line 6
int(1)
int(1)
Files: 1 - Size: 1024PHP Strict Standards:  Only variables should be passed by reference in D:\phpStudy\WWW\demo\fun_argc_refresh.php on line 6
PHP Strict Standards:  Only variables should be passed by reference in D:\phpStudy\WWW\demo\fun_argc_refresh.php on line 6

Output completed (0 sec consumed) - Normal Termination
相關文章
相關標籤/搜索