KernelPanic
KernelPanic

Reputation: 2432

php saving exec results into class's array

I have following php code chunk:

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
}

Now, I want to run ifconfig and save results into class's array. If I run this code, I get following errors:

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

Why does upper code does not work? I am newbie at php.

Upvotes: 0

Views: 25

Answers (1)

AbraCadaver
AbraCadaver

Reputation: 78994

This:

$this->$interfacesNames

Should be (notice no $ for the property):

$this->interfacesNames

Upvotes: 1

Related Questions