- var_dump: documentation ( source)
- unserialize: documentation ( source)
- memory_get_usage: documentation ( source)
- serialize: documentation ( source)
<?php
class A extends \stdClass {
public int $i = 42;
public function __unserialize($properties) {
foreach ($properties as $key => $property) {
$this->$key = $property;
}
}
}
$holder = [];
for ($i = 0; $i < 10000; $i++) {
$holder[] = new A;
}
var_dump(memory_get_usage());
foreach ($holder as $obj) {
}
var_dump(memory_get_usage());
$unserialized_holder = [];
foreach ($holder as $obj) {
$unserialized_holder[] = \unserialize(\serialize($obj));
}
unset($holder);
var_dump(memory_get_usage());