When trying to define an array such this:
$array = new SPLFixedArray(256);
for ($i = 0; $i < 256; $i++) {
$array[$i] = new SPLFixedArray(256);
for ($j = 0; $j < 256; $j++) {
$array[$i][$j] = new SPLFixedArray(5);
for ($k = 0; $k < 5; $k++) {
$array[$i][$j][$k] = 0;
}
}
}
I’m getting, only in CLI, “Segmentation Fault”. I read about such errors here on SO in C/C++, where is likely to be a memory problem and recommends to load everything to the heap memory with malloc(). In PHP do we have such tool?
This happens even in small 3d arrays, such as 15 instead of 256 (but works under 15).
Thanks!
Only a PHP bug would segfault; you should never be able to do that. It segfaults for me on PHP 5.3.5. I see nothing in 5.3.6’s change log that would indicate it has been fixed. (It crashes on 5.3.6 for me as well.)
As a workaround you could do this:
JK and K are constants.
JK = $jsize * $ksize;andK = $ksize.That’s likely to give you better performance than creating 3D arrays anyway.
Update:
I tried it on PHP 5.3.7-dev, and there is no segfault. So, fingers-crossed, it has been fixed and will work correctly in PHP 5.3.7.