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 'Not declared' . getCost(NotDefined::class) . PHP_EOL; // Output the cost WITH the property declared echo 'Declared' . getCost(PropertyDefined::class);

preferences:
30.53 ms | 402 KiB | 5 Q