Reputation: 619
When i try this in __construct:
var_dump($argc);
var_dump($argv);
var_dump($_SERVER["argv"]);
It returns error
Undefined variable: argc and
Undefined variable: argv
and array
(size=0) empty
When i declare $argc and $argv in global it returns all null.
Also i am parsing arguments using nncron like this:
* * * * * php \php\class.xmlcontroler.php timeout=60
0 * * * * php \php\class.xmlcontroler.php timeout=3600
What is solution?
Upvotes: 6
Views: 6623
Reputation: 7880
From PHP: $argc - Manual:
Note: This variable is not available when register_argc_argv is disabled.
So you have to enable the register_argc_argv
flag in your PHP configuration file.
Upvotes: 0
Reputation: 361
$argv
and $argc
are only available in the global namespace. You would have to handle them as a parameter to your constructor.
<?php
function foo()
{
var_dump($argv);
}
echo "global\n";
var_dump($argv);
echo "function\n";
foo();
Will provide:
global
array(2) {
[0]=>
string(5) "a.php"
[1]=>
string(3) "123"
}
function
NULL
when called like this php a.php 123
Update: Class example
<?php
class Foo
{
public function __construct($argv)
{
// use $argv
}
}
$foo = new Foo($argv);
Upvotes: 8