Bug #71656 [Opn->Dup]: Large static array initialization in class is truncated to 0x8000 entries
| From: | nikic@php.net | Date: | Tue, 23 Feb 2016 22:32:27 +0000 |
| Subject: | Bug #71656 [Opn->Dup]: Large static array initialization in class is truncated to 0x8000 entries | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-199435@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71656&edit=1
ID: 71656
Updated by: nikic@php.net
Reported by: laurentconstantin at free dot fr
Summary: Large static array initialization in class is
truncated to 0x8000 entries
-Status: Open
+Status: Duplicate
Type: Bug
Package: Class/Object related
Operating System: Linux
PHP Version: 5.6.18
Block user comment: N
Private report: N
New Comment:
Duplicate of https://bugs.php.net/bug.php?id=68057.
To bug isn't going to be fixed due to ABI compatibility restrictions. You'll have to
either avoid directly initializing static properties with large arrays or upgrade to PHP 7.
Previous Comments:
------------------------------------------------------------------------
[2016-02-23 21:58:46] laurentconstantin at free dot fr
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 this bug report at https://bugs.php.net/bug.php?id=71656&edit=1