# getopt bc break 5.2 -> 5.3

- Thread: https://externals.io/message/54463
- Original archive: https://news-web.php.net/php.internals/54463
- Started by martin@spuetz.net on 2011-08-08T11:40:02+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #54463 — martin@spuetz.net — 2011-08-08T11:40:02+00:00

URL: https://externals.io/message/54463#54463

Hello,

I have a lot legacy code that doesn't work with 5.3's getopt.

PHP 5.2.14 (cli) (built: Sep 24 2010 12:50:53)

$ php test.php Module.Controller.Action -p foobar
array(1) {
  ["p"]=>
  string(6) "foobar"
}

PHP 5.3.6 (cli) (built: Aug  8 2011 11:02:31):

$ php test.php Module.Controller.Action -p foobar
array(0) {
}

test.php:
var_dump(getopt("p:"));

Is this by-design?

Thanks,
Martin

---

## #54465 — Richard Quadling — 2011-08-08T12:09:00+00:00

URL: https://externals.io/message/54463#54465 · In reply to: #54463

> Hello,
>
> I have a lot legacy code that doesn't work with 5.3's getopt.
>
> PHP 5.2.14 (cli) (built: Sep 24 2010 12:50:53)
>
> $ php test.php Module.Controller.Action -p foobar
> array(1) {
>  ["p"]=>
>  string(6) "foobar"
> }
>
> PHP 5.3.6 (cli) (built: Aug  8 2011 11:02:31):
>
> $ php test.php Module.Controller.Action -p foobar
> array(0) {
> }
>
> test.php:
> var_dump(getopt("p:"));
>
> Is this by-design?
>
> Thanks,
> Martin

Can you try ...

php test.php -- Module.Controller.Action -p foobar


-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

---

## #54466 — martin@spuetz.net — 2011-08-08T12:25:47+00:00

URL: https://externals.io/message/54463#54466 · In reply to: #54465

> Can you try ...
> 
> php test.php -- Module.Controller.Action -p foobar

I tried

$ php test.php -p foobar -- Module.Controller.Action

that gave me:

array(1) {
  ["p"]=>
  string(6) "foobar"
}

But that doesn't help me much. I could add a prepend_file that would
convert $_SERVER["argv"] but I still have to edit a lot of old /
third-party code.

For now I hacked ext/standard/basic_functions.c:
> --- php-5.3.6-cli.o/ext/standard/basic_functions.c      2011-02-08 17:29:34.000000000 +0100
> +++ php-5.3.6-cli/ext/standard/basic_functions.c        2011-08-08 14:07:40.000000000 +0200
> @@ -4283,7 +4283,12 @@
>                                 arg_ptr = &arg;
>                         }
> 
> -                       argv[pos++] = estrdup(Z_STRVAL_P(arg_ptr));
> +                       char *s = estrdup(Z_STRVAL_P(arg_ptr));
> +                       if (pos == 1 && strlen(s) > 0 && s[0] != '-') {
> +                               argc--;
> +                       } else {
> +                               argv[pos++] = s;
> +                       }
> 
>                         if (arg_ptr != *entry) {
>                                 zval_dtor(&arg);

Martin
