-
Improvement
-
Resolution: Unresolved
-
Low
-
None
Since we started to use types in Moodle we have used a lot the nullable type so for example we used ?string to mean either a string or null value. Now that we can use union types (PHP 8.0), we can also use either ?string or null|string.
There is for now one example in core using union type: (https://github.com/moodle/moodle/blob/master/lib/adminlib.php#L3886), but there will be more and more example (I spotted one in one of the ticket I reviewed here)
The question is now: what would be the policy regarding this before we have too many examples to deal with ?
I would personally tend to use the nullable type ?string instead of null|string although it seems that the null|string would be in line with the phpdoc syntax for example.
This policy should apply to new code only.
Voting
Voting options
The following options are suggested for voting:
Voting options
Option A
Allow the two forms to coexist, so for example we could use ?string or null|string as method parameter, return value or class member type declaration. This is equivalent to the current situation.
Option B
Allow only the nullable type form for new code, i.e. ?string in all as method parameter, return value or class member type declaration.
Option C
Allow only the union type form for new code , i.e. null|string in all as method parameter, return value or class member type declaration.