Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting argc/argv and including a PHP CLI script

Tags:

php

If I've got a CLI script foo written in PHP that requires various command line options, can I invoke foo from another PHP script by first writing to $argv and $argc and then doing include('foo')? (Assume foo starts with <?php, not a hash-bang directive.)

Even if this would "work", why is it a bad idea? (apart from namespace collision).


1 Answers

It is not necessary to write anything into $argv /$argc - the variables will be available to the include like they are to the main script.

like image 117
Pekka Avatar answered May 23 '26 02:05

Pekka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!