我有以下php代码块:
class IFDisplayArch implements NIC
{
const CMD_HOSTNAME='hostname';
const CMD_GETINTERFACES="ifconfig | expand | cut -c1-8 | sort | uniq -u | awk -F: '{print $1;}'";
private $interfacesNames=array();
public function __construct()
{
// exec(sprintf(self::CMD_GETINTERFACES),
// self::$interfacesNames);
exec('ifconfig',
$this->$interfacesNames);
} // constructor
}
现在,我想运行ifconfig并将结果保存到类的数组中。如果我运行此代码,我会收到以下错误:
Notice: Undefined variable: interfacesNames in /srv/http/idaq/pages/network/lib/ifdisplay.arch.class.php on line 17
Fatal error: Cannot access empty property in /srv/http/idaq/pages/network/lib/ifdisplay.arch.class.php on line 17
为什么上层代码不起作用?我是php的新手。
答案 0 :(得分:1)
此:
$this->$interfacesNames
应该是(注意没有$
属性):
$this->interfacesNames