In php, what is the difference between the two following variable declarations, both for procedural mode and inside a class:
string $str; // without ? before the type
?string $str; // with ? before the type
Thank you for your lights
In php, what is the difference between the two following variable declarations, both for procedural mode and inside a class:
string $str; // without ? before the type
?string $str; // with ? before the type
Thank you for your lights
Variable $str
can only be of type string
:
string $str;
Variable $str
can be of type string
or null
:
?string $str;
"; $obj->var = null; echo "var of object after null assignment = " . $obj->var . "
"; ?>` this outouts: var of object = S123 var of object after null assignment = – Hamid ER-REMLI May 19 '21 at 13:48