我有一個PHP腳本,從文件fileRead2.php中調用函數fileRead2函數。PHP變量var_dump = NULL?
下面的函數讀取username.txt(哪個顯示是用戶名)。
VIM fileRead2.php
<?php
function fileRead2() {
global $fh, $line;
$fh = fopen('username.txt','r');
while ($line = fgets($fh)) {
// <... Do your work with the line ...>
echo($line);
}
fclose($fh);
}
?>
如果我上運行的Linux文件系統的Linux命令貓是本屆展會的 'tjones'(用戶名)。
我運行下面的腳本中。
<?php
// Read the Username
require_once('fileread2.php');
$userName = fileRead2();
echo $userName;
var_dump($userName);
>?
它呼應的$userName
該顯示器的「tjones」不過的var_dump展示的其作爲NULL輸出。
是否有任何理由爲什麼var_dump將$userName
變量顯示爲NULL,當它應該是字符串'tjones'?
我問的原因是因爲我需要變量$userName;
代碼的其他部分,因爲它是NULL沒有別的工作,我不知道爲什麼?
'var_dump'輸出本身,你不需要用'echo'使用它。 – Matthew