Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version | System time (s) | User time (s) | Memory (MiB) |
---|---|---|---|
8.4.10 | 0.040 | 0.011 | 17.85 |
<?php
class NumberContainer
{
public int $sum {
get => $this->prop1 + $this->prop2 + $this->prop3;
}
public function __construct(
public int $prop1 = 0 {
set(int $value) {
if ($value + ($this->prop2 ?? 0) + ($this->prop3 ?? 0) > 100) {
throw new \InvalidArgumentException("Setting prop1 to {$value} would make the sum exceed 100.");
}
$this->prop1 = $value;
}
},
public int $prop2 = 0 {
set(int $value) {
if (($this->prop1 ?? 0) + $value + ($this->prop3 ?? 0) > 100) {
throw new \InvalidArgumentException("Setting prop2 to {$value} would make the sum exceed 100.");
}
$this->prop2 = $value;
}
},
public int $prop3 = 0 {
set(int $value) {
if (($this->prop1 ?? 0) + ($this->prop2 ?? 0) + $value > 100) {
throw new \InvalidArgumentException("Setting prop3 to {$value} would make the sum exceed 100.");
}
$this->prop3 = $value;
}
},
) {}
}
$container = new NumberContainer();
echo "Initial sum: " . $container->sum . PHP_EOL;
echo "Setting prop1 to 30..." . PHP_EOL;;
$container->prop1 = 30;
echo "Current sum: " . $container->sum . PHP_EOL;
echo "Setting prop2 to 40..." . PHP_EOL;;
$container->prop2 = 40;
echo "Current sum: " . $container->sum . PHP_EOL;
echo "Setting prop3 to 20..." . PHP_EOL;;
$container->prop3 = 20;
echo "Current sum: " . $container->sum . PHP_EOL;
echo "Trying to set prop1 to 45 (sum would be 105)..." . PHP_EOL;
$container->prop1 = 45;
echo "Current sum: " . $container->sum . PHP_EOL;
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version | System time (s) | User time (s) | Memory (MiB) |
---|---|---|---|
8.4.10 | 0.040 | 0.011 | 17.85 |