- Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.14
- string(4) "yep2" string(3) "yep"
- Output for 7.4.0 - 7.4.33
- Parse error: syntax error, unexpected 'static' (T_STATIC) in /in/jZOVc on line 14
Process exited with code 255.
<?php
class Product {
private ?int $id;
private ?string $name;
private function __construct(?int $id = null, ?string $name = null) {
$this->id = $id;
$this->name = $name;
var_dump('yep2');
}
public static function fromBasicData(int $id, string $name): static {
$new = new static($id, $name);
var_dump('yep');
return $new;
}
}
$p1 = Product::fromBasicData(5, 'Widget');