I’m trying to execute this code:
JavaScript
x
function main(){
if ($argc < 1){
listDir(".");
}
else{
for($i = 0; $i <= sizeof($argv); $i++){
listDir($argv[$i]);
}
}
}
But I’m getting the following error:
PHP Notice: Undefined variable: argc in /home/me/test.php on line 15
I thought that $argv and $argc were global variables. How can I get rid of this error?
I’m running this from command line.
Advertisement
Answer
Add a
JavaScript
global $argc, $argv;
after
JavaScript
function main() {
Those variables are in global scope, but not in your function’s scope. The global keyword imports them.