<?php
class T { }
class X {
public function __construct(T $t) {
$this->t = $t;
}
}
class Builder
{
/**
* @var T|null
*/
public $t;
public function createX(): X
{
$this->validate();
// PHPStan complains that at this line, $this->t could be null, except we've already checked it isn't...
// Parameter #1 $t of class X constructor expects T, T|null given.
return new X($this->t);
}
private function validate()
{
if (is_null($this->t)) {
throw new \Exception;
}
}
}
$builder = new Builder;
$builder->t = new T;
$builder->createX();
Deprecated: Creation of dynamic property X::$t is deprecated in /in/WkL0Y on line 7
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Deprecated: Creation of dynamic property X::$t is deprecated in /in/WkL0Y on line 7