3v4l.org

run code in 300+ PHP versions simultaneously
<?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 getCost(NotDefined::class) . PHP_EOL; // Output the cost WITH the property declared echo getCost(PropertyDefined::class);
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.26, 7.3.0 - 7.3.13, 7.4.0 - 7.4.1
416 bytes 56 bytes
Output for 5.6.0 - 5.6.40
504 bytes 256 bytes

preferences:
132.76 ms | 401 KiB | 157 Q