- Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.25, 7.3.0 - 7.3.12, 7.4.0
- Not declared416 bytes Declared56 bytes
- Output for 5.6.0 - 5.6.40
- Not declared488 bytes Declared256 bytes
<?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);