php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #418 array function misbehaves if first element is a string containing a number
Submitted: 1998-05-29 21:56 UTC Modified: 1998-05-30 03:40 UTC
From: sam at daemoninc dot com Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0 Release Candidate 5 OS: Solaris 2.5.1
Private report: No CVE-ID: None
 [1998-05-29 21:56 UTC] sam at daemoninc dot com
A string containing a number is being treated the same as a number.

Reproduce with:

$a = array("0", "a", "b");
for (reset($a); $v = current($a); next($a)) {
    echo "$v\n";
}

I would expect this to print three lines with three strings:
0
a
b
instead it prints nothing at all.  If the first string is changed from
"0" to "z", it prints three lines as expected.  Looks like the string
"0" is being treated the same as the number 0.

do-conf contains:
./configure --with-gd=no --with-sybase=/tools1/pkgs/sybase --with-config-file-path=/web/cgi-bin/RC_internal/phpdir/lib --enable-debug=no --enable-safe-mode=yes --with-exec-dir=/web/cgi-bin/RC_internal/phpdir/scripts --bindir=/web/cgi-bin/RC_internal/phpdir/bin

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1998-05-30 03:40 UTC] zeev
You're expectations are wrong.  "0" is false, thus your
loop will have no iterations at all, which is exactly
what should happen.
For reliable array traversal code, look at each() (at
the online documentation or at the php3 mailing list
archives).

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 10:01:30 2024 UTC