有没有办法使用从另一个类调用的静态方法设置public var,所以稍后我的类Photo我可以将它用作$ this-> type?
class Photo
{
public $type;
public static function create($file, $title, $alt, $type): self
{
$photo = new static();
$photo->file = $file;
$photo->title = $title;
$photo->alt = $alt;
$photo->type = $type; // passed string 'gallery'
return $photo;
}
public function myFunc() {
echo $this->type; // getting null
}
}