1

I'm working on a command-line script for a php app.

I can't get it to successfully accept params.

(via ssh)
If I type:
/: php testFile.php arg1 arg2 arg3

I receive the following errors: Notice: Undefined variable: agrc in /testFile.php on line 3 Notice: Undefined variable: agrv in /testFile.php on line 3

Here's the current code:

<?php
echo ini_get('register_argc_argv');
print_r( $agrc );print_r( $agrv );
?>

I also confirmed that the 'register_argc_argv' directive is TRUE

What am I over looking ?

Thanks in advance.

2
  • You check for the argc and argv setting, and then try to debug agrc and agrv. Look at those variable names again. Commented Jan 8, 2014 at 21:08
  • You spelt argv and argc wrong in your code. Commented Jan 9, 2014 at 10:02

1 Answer 1

2

Use $_SERVER['argv'] instead of only $agrv.

Sign up to request clarification or add additional context in comments.

5 Comments

We don't use CGI anywhere in the app now, and the php-cgi binary is not on our server. I believe this can be done using the cli, as well as cgi. Have I misunderstood the cli ?
Have tried to add #!/usr/bin/php -q to the first line of your file , even before the php tag (<?php) ? I've updated the answer, check it out.
Copy & paste your example and it fails - while . Also added the declaration line up top, to no avail. Possibly a directives issue ?
Try your original code but use $_SERVER['argc'] instead of only $agrc. Does it work ?
A quick var_dmup shows me it's in $_SERVER['agrv'] , that'll work. Thanks Tuga !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.