php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #29714 getopt does not reset
Submitted: 2004-08-17 01:05 UTC Modified: 2006-04-03 14:02 UTC
From: lists at cyberlot dot net Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 5.0.0 OS: Fedora Core 2
Private report: No CVE-ID: None
 [2004-08-17 01:05 UTC] lists at cyberlot dot net
Description:
------------
You can only call getopt a single time and get results. Getopt should reset what ever pointers it uses to ensure state is as it was prior to calling getopt.

An example.. A modular based system using a config file or command line to load a module, It is impossible for the module to use getopt to look for module specific settings because getopt has already been called by the main engine.

./engine -loadmod abc -abcdb 123

It is impossible for mod abc to realize it needs to load database 123 because any attempts to run getopt based on those new params fail.

Reproduce code:
---------------
<?
    $cl_input = getopt('c:h');
    print_r($cl_input);
    $cl_input = getopt('c:h');
    print_r($cl_input);
?>


Expected result:
----------------
[root@fs streams]# php test.php -c 1
Array
(
    [c] => 1
)
Array
(
    [c] => 1
)


Actual result:
--------------
[root@fs streams]# php test.php -c 1
Array
(
    [c] => 1
)
Array
(
)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-03 14:02 UTC] tony2001@php.net
Fixed in 5.1.2
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 21:01:33 2025 UTC