A question mark before the parameter method this is a bug in PHP?

0 like 0 dislike
12 views
Met someone else's code such a thing.
The functionality works fine, but the IDE highlights the error.
Is it a real error ? that might mean?
5ae6d093d95e1581548878.png
by | 12 views

4 Answers

0 like 0 dislike
Types for parameters and return values can be marked as nullable by adding a prefix in the form of a question mark. This means that the parameters and return values can be specified type or NULL.

\rphp.net/manual/ru/migration71.new-features.php
by
0 like 0 dislike
No, it means the same as ($par=null)
In other words - an optional parameter.
by
0 like 0 dislike
The question mark means that the parameter can accept the specified type or null
by
0 like 0 dislike
In other words - an optional parameter.

Actually - no.
The question mark indicates that the parameter must be either null or the specified type. But let him not
function test (?stdClass $obj) { // some code } test(new stdClass); // ok test(null); //ok test(); // error


In the example in the question parameter is really optional, as indicated by the default value.
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
4 answers
110,608 questions
257,186 answers
0 comments
33,795 users