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
What is ARGV? As a concept, ARGV is a convention in programming that goes back (at least) to the C language. It refers to the “argument vector,” which is basically a variable that contains the arguments passed to a program through the command line.
$argv — Array of arguments passed to script.
As you can see, the first argument ( argv[0] ) is the name by which the program was called, in this case gcc . Thus, there will always be at least one argument to a program, and argc will always be at least 1.
That means argc/argv aren't superglobals - they're only visible at the top-level context of PHP scripts, so...
<?php
$x = $argv[1]; // works
class foo {
function bar() {
echo $argv[1]; // undefined
}
function baz() {
global $argv;
echo $argv[1]; // works
}
}
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