PHP 将 exec 结果保存到类的数组中


php saving exec results into class's array

我有以下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的新手。

这个:

$this->$interfacesNames

应该是(请注意没有$属性):

$this->interfacesNames