php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39383 PHP erroneously converts keys to integer
Submitted: 2006-11-04 20:33 UTC Modified: 2006-11-04 22:44 UTC
From: lamotkin at softhome dot net Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2.0 OS: Windows 98
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: lamotkin at softhome dot net
New email:
PHP Version: OS:

 

 [2006-11-04 20:33 UTC] lamotkin at softhome dot net
Description:
------------
PHP erroneously converts keys to integer if possible,
but my script is type-sensitive with that code.


Reproduce code:
---------------
$Test =
array(	"" => "No set",
	"1" => "Yes",
	"0" => "No");
var_dump($Test);
echo "<p>";
$Test =
array(	"" => "No set",
	1 => "Yes",
	0 => "No");
var_dump($Test);
echo "<p>";


Expected result:
----------------
'var_dump's must NOT be the same


Actual result:
--------------
'var_dump's ARE the same


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-04 20:38 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 [2006-11-04 21:21 UTC] lamotkin at softhome dot net
Well, you are right, Derick, the doc covered the issue.
But I believe this is a software design error,
because neither

        in_array($some_var, $Test, true)
nor
        in_array($some_var, $Test, false)

produces no correct results.
But if array keys would be of the type specified
on definition, the

        in_array($some_var, $Test, true)

work right.
 [2006-11-04 21:45 UTC] derick@php.net
Maybe, but we can't just start breaking things for people so we ain't changing this.
 [2006-11-04 22:44 UTC] lamotkin at softhome dot net
Oops, I realized a nonsense in my logic,
the 'in_array' in examples above search
for the values, not keys, and they probably
will work right.
I corrected my real script (which implies
a bit more complicated code), and the
described is not an issue for me now ...

Sorry, Derick, for wasting your precious
time.
Please delete this "bug"
from the database.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 08:01:35 2024 UTC