0

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.

1 Answer 1

1

This:

$this->$interfacesNames

Should be (notice no $ for the property):

$this->interfacesNames
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.