سلام خسته نباشید
معنی ? در کد زیر چیه ؟
توی داکیومنت php
https://www.php.net/manual/en/language.oop5.properties.php
<?php
class User
{
public int $id;
public ?string $name;
public function __construct(int $id, ?string $name)
{
$this->id = $id;
$this->name = $name;
}
}
$user = new User(1234, null);
var_dump($user->id);
var_dump($user->name);
?>
سلام و احترام
به این معنیه که میتونه اون متغیر null باشه، اگه هم به new کردن کلاس دقت کنید
$user = new User(1234, null);
مقدار دوم null داده که مقدار دوم همون پارامتر name هستش و خروجی که در ادامه کد از name گرفته null هستش
var_dump($user->name); // output: NULL
spl_autoload_register ( callable $autoload_function = ? , bool $throw = true , bool $prepend = false ) : bool