Bug #71656 [NEW]: Large static array initialization in class is truncated to 0x8000 entries
| From: | laurentconstantin at free dot fr | Date: | Tue, 23 Feb 2016 21:58:47 +0000 |
| Subject: | Bug #71656 [NEW]: Large static array initialization in class is truncated to 0x8000 entries | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-199434@lists.php.net to get a copy of this message | ||
From: laurentconstantin at free dot fr
Operating system: Linux
PHP version: 5.6.18
Package: Class/Object related
Bug Type: Bug
Bug description:Large static array initialization in class is truncated to 0x8000 entries
Description:
------------
The test script creates a class containing a large static array
initialization like :
class MyClass {
public static $arr = array('a0'=>1,'a1'=>1,'a2'=>1,etc.
}
Then, running the created test script shows that the created array
is smaller than the expected array.
If the number of entries in this array is larger than 32768 (0x8000),
then the lower 32768 entries are lost. So, for example the a0 to a32768
entries are not in the array, and the a32769... entries are in the
array.
PHP was compiled with :
./configure --prefix=/usr/local/phpTest
make
make install
Test script:
---------------
<?php
$numberOfEntries = $argv[1]; // Use for example '35000'.
$code = "<?php\n";
$code .= "class MyClass {\n";
$code .= " public static \$arr = array(\n";
for ($i = 0 ; $i < $numberOfEntries ; $i++) {
if ($i != 0) {
$code .= ",";
}
$code .= "'a$i'=>1";
}
$code .= " );\n";
$code .= "}\n";
$code .= "print \"Number of entries in the array:
\".count(MyClass::\$arr).\"\\n\";\n";
$code .= "?>\n";
file_put_contents('./myclass.php', $code);
/*
Then run in a shell:
php bug.php 35000 # This creates the myclass.php file.
php myclass.php # This shows the number of entries in the array.
> Number of entries in the array: 2232 <- it should say 35000
instead.
Note: 35000-2232 = 32768 = 0x8000.
So, this is the proof that the array is truncated, and lost its first
0x8000 entries.
*/
?>
Expected result:
----------------
After running:
php bug.php 35000
The second script is run:
php myclass.php
This second script should display:
Number of entries in the array: 35000
However, it displays:
Number of entries in the array: 2232
Note: 35000-2232 = 32768 = 0x8000.
--
Edit bug report at https://bugs.php.net/bug.php?id=71656&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71656&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71656&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71656&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71656&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71656&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71656&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71656&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71656&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71656&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71656&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71656&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71656&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71656&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71656&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71656&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71656&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71656&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71656&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71656&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71656&r=mysqlcfg