: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
public function __construct($keys){
public function push($val){ //associative array with keys that match those given to constructor
foreach($this->keys as $key){
$this->data .= pack('N', wfUtils::strlen($val[$key])) . $val[$key];
public function shift(){ //If you alternately call push and shift you must periodically call collectGarbage() or ->data will keep growing
if(wfUtils::strlen($this->data) < 1){ return null; }
if($this->shiftPtr == wfUtils::strlen($this->data)){ return null; }
foreach($this->keys as $key){
$len = unpack('N', wfUtils::substr($this->data, $this->shiftPtr, 4));
$arr[$key] = wfUtils::substr($this->data, $this->shiftPtr + 4, $len);
$this->shiftPtr += 4 + $len;
if($this->shiftPtr == wfUtils::strlen($this->data)){ //garbage collection
$this->data = ""; //we don't shorten with substr() because the assignment doubles peak mem
public function collectGarbage(){ //only call collectGarbage if you're alternating between pushes and shifts and never emptying the array.
//If you don't collect garbage then the data that is shifted is never freed
$this->data = wfUtils::substr($this->data, $this->shiftPtr); //at this point memory usage doubles because of the = assignment (string copy is made), so try not to call collect garbage unless you have to.
public function zero(){ //Rather call this instead of collect garbage because it's way more mem efficient.