背景:当用popen打开多个command时会出现重用变量,二是会用连字符进行连接command返回的变量,两次popen会有两个地方出现问题。
$handle = popen($command, "r");
do {
$excuteResult = fread($handle, 2024);
if (strlen($excuteResult) == 0) {
pclose($handle); //关闭pipe
break;
}
$excuteResultAll .= $excuteResult;
} while (true);
//这儿用到的$excuteResultAll 变量,下面还要用,防止污染,则需要给NULL值清空,用unset后需要再定义一次相同的变量,否则会出现:
Undefined variable: excuteResultAll in /data/htdocs/jackxiang.com/index.php on line 354
do {
$excuteResult = fread($handle, 2024);
if (strlen($excuteResult) == 0) {
pclose($handle); //关闭pipe
break;
}
$excuteResultAll .= $excuteResult;
} while (true);
______________________________小demon实践如下:______________________________
php null.php
<?php
$foo = "";
$foo = "jack";
unset($foo);
$foo .= "xiang";
$vars = get_defined_vars();
通过unset后,$foo变量用点连接时运行如下:
[22-Sep-2014 14:29:59 Asia/Shanghai] PHP Notice: Undefined variable: foo in /tmp/null.php on line 6
[foo] => xiang
而不用unset而用NULL后:
<?php
$foo = "";
$foo = "jack";
$foo = NULL;
//unset($foo);
$foo .= "xiang";
$vars = get_defined_vars();
print_r($vars);
解决了这个变量的问题:
[foo] => xiang
说明这样做是可行的,完毕。
$handle = popen($command, "r");
do {
$excuteResult = fread($handle, 2024);
if (strlen($excuteResult) == 0) {
pclose($handle); //关闭pipe
break;
}
$excuteResultAll .= $excuteResult;
} while (true);
//这儿用到的$excuteResultAll 变量,下面还要用,防止污染,则需要给NULL值清空,用unset后需要再定义一次相同的变量,否则会出现:
Undefined variable: excuteResultAll in /data/htdocs/jackxiang.com/index.php on line 354
do {
$excuteResult = fread($handle, 2024);
if (strlen($excuteResult) == 0) {
pclose($handle); //关闭pipe
break;
}
$excuteResultAll .= $excuteResult;
} while (true);
______________________________小demon实践如下:______________________________
php null.php
<?php
$foo = "";
$foo = "jack";
unset($foo);
$foo .= "xiang";
$vars = get_defined_vars();
通过unset后,$foo变量用点连接时运行如下:
[22-Sep-2014 14:29:59 Asia/Shanghai] PHP Notice: Undefined variable: foo in /tmp/null.php on line 6
[foo] => xiang
而不用unset而用NULL后:
<?php
$foo = "";
$foo = "jack";
$foo = NULL;
//unset($foo);
$foo .= "xiang";
$vars = get_defined_vars();
print_r($vars);
解决了这个变量的问题:
[foo] => xiang
说明这样做是可行的,完毕。
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/7511/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
评论列表