Edit report at https://bugs.php.net/bug.php?id=64086&edit=1

 ID:                 64086
 Updated by:         der...@php.net
 Reported by:        jessewalker at gmail dot com
 Summary:            Quirks with array entries 08 / 8 and 09 / 9 compared
                     to other entries.
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Arrays related
 Operating System:   Linux
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

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


Previous Comments:
------------------------------------------------------------------------
[2013-01-27 21:40:25] 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


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



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

Reply via email to