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?
$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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With