3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class NotDefined { public function setDirection($direction) { $this->direction = $direction; } public function getDirection() { return $this->direction; } } class PropertyDefined { protected $direction; public function setDirection($direction) { $this->direction = $direction; } public function getDirection() { return $this->direction; } } function getCost($class) { $start = memory_get_usage(); $instance = new $class; $instance->setDirection('asc'); $cost = memory_get_usage() - $start . ' bytes'; unset($instance); return $cost; } // Output the cost WITHOUT a property declared echo 'Not declared' . getCost(NotDefined::class) . PHP_EOL; // Output the cost WITH the property declared echo 'Declared' . getCost(PropertyDefined::class);
based on h7nVV
Output for 7.0.0 - 7.2.6
Not declared416 bytes Declared56 bytes
Output for hhvm-3.15.4
Not declared0 bytes Declared0 bytes
Output for 5.6.0 - 5.6.30
Not declared488 bytes Declared256 bytes