我有一个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