ID:               35713
 Updated by:       [EMAIL PROTECTED]
 Reported By:      nalkat at yahoo dot com
 Status:           Open
-Bug Type:         Scripting Engine problem
+Bug Type:         CGI related
 Operating System: Linux
 PHP Version:      5.1.1
 New Comment:

This code works perfectly fine:
$array = array(1=>1);
var_dump(isset($array["1"]));
var_dump(isset($array[1]));

The problem is that getopt() adds array elements with numeric indexes
as strings.


Previous Comments:
------------------------------------------------------------------------

[2005-12-16 19:32:50] nalkat at yahoo dot com

This is definately a bug in PHP itself.  I would be willing to bet that
no matter where you attempted this code snippet, it will still not work
(CLI/CGI/Web/etc).

If there is further information that you require to get this resolved,
I would be more than happy to help.

------------------------------------------------------------------------

[2005-12-16 17:51:48] [EMAIL PROTECTED]

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.



------------------------------------------------------------------------

[2005-12-16 17:30:38] nalkat at yahoo dot com

Description:
------------
When dealing with arrays indexed by a numerical string (i.e.
$array['1']) and then attempting to use isset or similar on the value,
results are not as expected.

As you can see from the example below, it would be impossible to use
something such as:

$opts = getopt("1:2:a:b:");
if (isset($opts['1'])) {
  do_something();
}
if (isset($opts['2'])) {
  do_something_else();
}
if (isset($opts['a'])) {
  echo "works\n";
}
...
...

Reproduce code:
---------------
<?

// test.php

$opts = getopt("1:2:3:4:a:");
if (isset($opts['1'])) {
        echo "it worked for 1!\n";
}
if (isset($opts['a'])) {
        echo "it worked for a!\n";
}
var_dump ($opts);
?>

(host)# php -q test.php -1 hi -a bye

Expected result:
----------------
EXPECTED:
-----------
it worked for 1!
it worked for a!
array(2) {
  ["1"]=>
  string(2) "hi"
  ["a"]=>
  string(3) "bye"
}


Actual result:
--------------
ACTUAL:
-----------
it worked for a!
array(2) {
  ["1"]=>
  string(2) "hi"
  ["a"]=>
  string(3) "bye"
}



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=35713&edit=1

Reply via email to