3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Foo { private $foo = ["a" => 1, "b" => 2, "c" => 3, "d" => 4]; } $i = 0; $mem = memory_get_usage(); for ($i = 19999; --$i;) { $s[] = new Foo; } $mem = memory_get_usage() - $mem; echo "Memory used with static init: ", $mem, PHP_EOL; class Bar { private $bar; function __construct() { $this->bar = ["a" => 1, "b" => 2, "c" => 3, "d" => 4]; } } $mem = memory_get_usage(); for ($i = 19999; --$i;) { $f[] = new Bar; } $mem = memory_get_usage() - $mem; echo "Memory used with dynamic init: ", $mem, PHP_EOL;
based on llpgA
Output for 7.1.0 - 7.3.0
Memory used with static init: 2426568 Memory used with dynamic init: 2434760
Output for 7.0.0 - 7.0.33
Memory used with static init: 2426568 Memory used with dynamic init: 9954008
Output for 5.6.0 - 5.6.38
Memory used with static init: 6614080 Memory used with dynamic init: 21878576
Output for 5.5.0 - 5.5.38
Memory used with static init: 6614104 Memory used with dynamic init: 21878520