php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64086 Quirks with array entries 08 / 8 and 09 / 9 compared to other entries.
Submitted: 2013-01-27 21:40 UTC Modified: 2013-01-27 22:00 UTC
From: jessewalker at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jessewalker at gmail dot com
New email:
PHP Version: OS:

 

 [2013-01-27 21:40 UTC] jessewalker at gmail dot com
Description:
------------
I'd set up a multi-dimensional array with the first level having 12 entries 01 to 12 (months), and the second level having 01 to 31 (days) depending on the month.

e.g.,
$months[01][01] = "...";
...
$months[01][31] = "...";
$months[02][01] = "...";
...
$months[02][28] = "...";
...

I found that when iterating through $months with:

foreach($months[1] as $day => $entry)

and just printing out the $day value, that I'd get results like:

1
..
7
0
10
..
31

Notice that 8 and 9 don't print out, but 0 (zero) instead. All other numbers are fine.

I tested this all the way up to $months[12] and get the same result, though it fails miserably on $months[8] and $months[9] with the following:

PHP Notice:  Undefined offset: 8 in /home/pi/php/test.php on line 10
PHP Warning:  Invalid argument supplied for foreach() in /home/pi/php/test.php on line 10

Remember that I set my $months array up with 08 and 09 (same as the other numbers having a leading zero).

So it's not just an issue at the 2nd level of a multi-dimensional array.

With this in mind I reduced my test code down and still get the same issue. It's not only a multi-dimensional array issue, but an array issue affecting entries 8 and 9. The multi-dimensional array gives a slightly different result, so this is why I've mentioned it first.

I get the exact same results with:
PHP 5.3.6-13ubuntu3.9 with Suhosin-Patch (cli) (built: Sep 12 2012 19:02:11) -- from XBMCbuntu on an HP ProLiant MicroServer N40L
PHP 5.6.0-dev (cli) (built: Jan 27 2013 20:37:53) -- from Git master, on the same box I run XBMCbuntu on
PHP 5.4.4-11 (cli) (built: Jan 18 2013 02:49:29) -- from Raspbian "Wheezy" 2012-12-16 on a Raspberry Pi
All systems fully up to date using apt-get.

I ran my tests from the CLI with `php test.php`, and the Git test with `/opt/bin/php test.php`.

I know that I could just not set my arrays up with 01..09, and use 1..9 instead - though it's still a quirky issue all the same.

Is there any explanation for this, or am I missing something?

I'm more than happy to provide full code if requested. The test code provided should be enough to get some idea.

Test script:
---------------
<?php

$num[1] = "One";
$num[01] = "ZeroOne";
$num[02] = "ZeroTwo";
$num[2] = "Two";

$num[8] = "Eight";
$num[08] = "ZeroEight";
$num[09] = "ZeroNine";
$num[9] = "Nine";

print("1: ".$num[1]."\r\n");
print("01: ".$num[01]."\r\n");
print("02: ".$num[02]."\r\n");
print("2: ".$num[2]."\r\n");
print("8: ".$num[8]."\r\n");
print("08: ".$num[08]."\r\n");
print("09: ".$num[09]."\r\n");
print("9: ".$num[9]."\r\n");

?>

Expected result:
----------------
1: ZeroOne
01: ZeroOne
02: Two
2: Two
8: ZeroEight
08: ZeroEight
09: Nine
9: Nine

Actual result:
--------------
1: ZeroOne
01: ZeroOne
02: Two
2: Two
8: Eight
08: ZeroNine
09: ZeroNine
9: Nine

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-27 21:48 UTC] derick@php.net
-Status: Open +Status: Not a bug
 [2013-01-27 21:48 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

Numbers starting with a 0 are octal numbers, and "8" is not a valid character in octal representation: http://en.wikipedia.org/wiki/Octal
 [2013-01-27 22:00 UTC] jessewalker at gmail dot com
Derick! Long time no chat (PHP London way back when). Thanks for pointing out how foolish I am. I'm sorry for troubling you with this matter :(
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 17:01:34 2025 UTC