-
Task
-
Resolution: Fixed
-
Low
Since 02nd April 2020, this has been agreed:
(matching the PSR-12)
1) No whitespace between the nullable character (question mark -?) and params or return types.
2) No whitespace between the function closing brackets and the colon.
With an image speaking a thousand words. Correct:
public function foo(string $bar, ?int $baz): ?bool {}
|
Since PHP 7.0 it's possible to specify returning types to functions & methods (examples from php.net):
function sum($a, $b): float {
|
return $a + $b;
|
}
|
More yet, since PHP 7.1 (so, eligible for Moodle 3.7 and up) it's also possible to use the nullify operator to allow also nulls to be returned:
function sum($a, $b): ?float {
|
return $a + $b;
|
}
|
This issue (followup of MDLSITE-5660) is about to decide if we want to rule how to write code using those return types, both spacing and the "?" symbol. Basically, between:
A) function xxx(): [?]int <<== default syntax used in php site
B) function xxx() : [?]int <<== already used syntax in core - privacy stuff mainly
C) Current status, unruled. Basically any number of chars is allowed. See this fixture file to view all the crazy possibilities.
Ciao
- Discovered while testing
-
MDLSITE-5660 Codechecker problems with PHP 7 function return types declaration
-
- Closed
-
- has a non-specific relationship to
-
MDLSITE-5972 Require type hints and return type declarations
-
- Closed
-
- has been marked as being related by
-
CONTRIB-8043 Ensure that whitespace rules about function hinted return types and params are enforced
-
- Closed
-
-
MDLSITE-5972 Require type hints and return type declarations
-
- Closed
-
- has to be done after
-
MDLSITE-5879 Respect PSR-1, and PSR-12 where no existing rule exists
-
- Closed
-
- has to be done before
-
MDLSITE-6096 One webservice (external function) per class (voting ends: April 21 00:00 UTC)
-
- Closed
-
- is duplicated by
-
MDL-61593 Coding style for return types
-
- Closed
-