Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP CLI: remove last element from ARGV

Tags:

php

argv

I am not sure if this is possible, but I need to make a dirty hack. Assume I am invoking php from cli

php script.php one two

then in script.php I am doing something with two parameter, and then I would like to remove it, so the third party code that is included later on thought, that the initial command was

php script.php one

I tried unset($argv[2]) and unset($GLOBALS['argv'][2]) but this does not work. Is it after all possible what I am trying to do ?

UPDATE: Does not work = I get exception from third party code "Too many arguments"

UPDATE: of course it should be argv[1], but it is a typo only in this question, not in the actual problem. Please assume I have written argv[1] :)

like image 337
mkk Avatar asked Mar 17 '26 09:03

mkk


1 Answers

You're trying to remove the third element with unset($argv[2]).

Array are zero-based. So to remove the second element use:

unset($argv[1])

like image 105
Marco Balk Avatar answered Mar 18 '26 23:03

Marco Balk



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!