$ argv in class

I use exec() to execute the 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 the class.

It says:

Note that $ argv and $ argc must be declared global when trying to access the class method

on php.net

+6
source share
1 answer

This means that argc / argv are not superglobals - they are visible only in the context of top-level PHP scripts, so ...

 <?php $x = $argv[1]; // works class foo { function bar() { echo $argv[1]; // undefined } function baz() { global $argv; echo $argv[1]; // works } } 
+20
source

Source: https://habr.com/ru/post/922681/


All Articles