SplFixedArray is a data structure provided by the Standard PHP Library(SPL). Works similar to the array but is memory efficient. So when memory consumption is a concern in some part of your PHP application then use SplFixedArray instead of standard array.
SplFixedArray class provides a fixed size array. It can be resized, but has to resized manually.
NOTE
Benefits of SplFixedArray over Array
What are the benefits of using SplFixedArray instead of a normal array in PHP?
SplFixedArray Capability/Rules
SplFixedArray can do
SplFixedArray can not do
Interface Declaration
We can declare an interface by using the keyword “interface”.
Following is a valid interface declaration-
<?php
interface BigBoxInterface {
}
Add Method Declaration to Interface
All methods declared in an interface must be public.
Add function declaration to interface-
<?php
function xrange(int $start, int $end, int $step = 1) {
$chunkSize = 100;
$indexCounter = 0;
$data = new SplFixedArray($chunkSize);
for($i = $start; $i <= $end; $i++) {
$data[$indexCounter++] = $i;
if ($indexCounter === $chunkSize) {
yield $data;
$data = new SplFixedArray($chunkSize);
$indexCounter = 0;
}
}
if ($data->count()) {
yield $data;
}
}
// Demo
foreach(xrange(1, 956) as $chunk) {
var_dump($chunk);
}
WARNING
If the method is not declared public then we get a Fatal Error with the message-
PHP Fatal error: Access type for interface method
BigBoxInterface::myFunc() must be public
in test.php on line 4