$argv in a class

Viewed 6167

I'm using exec() to exec a file but the file is in a class, I read more about argv but it was confusing. I need to get it to work inside a class.

It says:

Please note that, $argv and $argc need to be declared global, while trying to access within a class method

on php.net

2 Answers

i add argv as arguments to the class constructor

class MyClass
{
    protected $args;

    public function __construct($args) 
    {
        $this->args = $args;
    }

    public function foo()
    {
        $this->args[1]; //access args using $this->args
    }
}

$myClass = new MyClass($args);
Related