ID: 35713
User updated by: nalkat at yahoo dot com
Reported By: nalkat at yahoo dot com
-Status: Feedback
+Status: Open
Bug Type: Scripting Engine problem
Operating System: Linux
PHP Version: 5.1.1
New Comment:
Tony:
Ok this is what I am seeing. When I attempt to assign the numerical
string index to the array manually PHP converts that numerical value to
an actual number.
It would appear that you are correct that getopt is causing the
problem, however, I still feel that it is a PHP core problem that is
allowing this behavior to occur.
try this snippet:
<?php
$array = array();
$array['1'] = "blah";
if (isset($array['1'])) {
echo "the test condition worked\n";
}
var_dump($array);
unset ($array);
$array = getopt("1:");
if (isset($array['1'])) {
echo "the test condition worked\n";
}
var_dump($array);
?>
You will notice that the test condition fails when the variable is
being assigned by getopt, but not when it is assigned manually. You
will also notice in the output of the var_dumps that the manual
assignment converts the numerical string to an actual number whereas
the getopt version does not.
You tell me.. is this a PHP problem of allowing the numerical string
index to be assigned or merely a getopt problem where this is actually
occuring?
At anyrate, should I be able to use getopt with a numerical
command-line argument? Is there some kind of work around?
Previous Comments:
------------------------------------------------------------------------
[2005-12-16 20:04:55] [EMAIL PROTECTED]
>you can create an array with a numerical string index
> value, and you will still have the same problem.
Eh? What are you talking about?
>and if you will notice, from your example code snippet,
>you are not doing a test on the value of the array element.
Did you try to execute it?
What kind of notice you get with this code?
<?php
$array = array(1=>1);
var_dump(isset($array["1"]));
var_dump(isset($array[1]));
?>
------------------------------------------------------------------------
[2005-12-16 19:59:44] nalkat at yahoo dot com
and if you will notice, from your example code snippet, you are not
doing a test on the value of the array element. You are merely
assigning it. Attempt to do some kind of validation... does it work?
------------------------------------------------------------------------
[2005-12-16 19:56:08] nalkat at yahoo dot com
I dont think its a problem of getopt adding numerical string indexes,
because you can create an array with a numerical string index value,
and you will still have the same problem.
If what you say truely is the case, then it is still a problem with the
PHP core itself allowing this action.
I think the real problem here is that when you are attempting to access
an array element with a numerical string as the index value, PHP is not
seeing it as a string when enclosed in quotes, but rather it is
converting the numerical string to a numerical literal.
------------------------------------------------------------------------
[2005-12-16 19:49:27] [EMAIL PROTECTED]
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.
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/35713
--
Edit this bug report at http://bugs.php.net/?id=35713&edit=1