com php-langspec: Add nullable types: spec/13-functions.md spec/19-grammar.md

From: Date: Tue, 19 Sep 2017 06:34:50 +0000
Subject: com php-langspec: Add nullable types: spec/13-functions.md spec/19-grammar.md
Groups: php.standards.cvs 
Request: Send a blank email to standards--cvs+get-389@lists.php.net to get a copy of this message
Commit: 287030c352f0019a2f9dee2077ad146d0d3e3e8c Author: Nikita Popov <nikic@php.net> Tue, 19 Sep 2017 08:34:50 +0200 Parents: 9cf8b200e55968b9e542c6cb70563d35ec347bf8 Branches: master Link: http://git.php.net/?p=php-langspec.git;a=commitdiff;h=287030c352f0019a2f9dee2077ad146d0d3e3e8c Log: Add nullable types Fixed #196. Bugs: https://bugs.php.net/196 Changed paths: M spec/13-functions.md M spec/19-grammar.md Diff: diff --git a/spec/13-functions.md b/spec/13-functions.md index 3e253de..6d46b01 100644 --- a/spec/13-functions.md +++ b/spec/13-functions.md @@ -77,6 +77,9 @@ return-type: ':' 'void' type-declaration: + '?'? base-type-declaration + +base-type-declaration: 'array' 'callable' 'iterable' @@ -123,6 +126,9 @@ default-argument-specifier: : void <i id="grammar-type-declaration">type-declaration:</i> + ?<sub>opt</sub> <i><a href="#grammar-base-type-declaration">base-type-declaration</a></i> + +<i id="grammar-base-type-declaration">base-type-declaration:</i> array callable iterable @@ -218,7 +224,9 @@ Parameters typed with *scalar-type* are accepted if they pass the type check for as [described below](#type-check-modes). Once the checks have been passed, the parameter types are always of the scalar type specified (or NULL if NULL is allowed). -If a parameter has a type declaration, NULL is not accepted unless it has a default value that evaluates to NULL. +If a parameter has a type declaration, NULL is not accepted unless the +type is nullable. A type is nullable if it is prefixed with ? or if the +parameter has a default value that evaluates to NULL. The default value for a typed parameter must be of the type specified, or NULL, and conversion is not be performed for defaults, regardless of the mode. diff --git a/spec/19-grammar.md b/spec/19-grammar.md index 0cc0a9a..16c007e 100644 --- a/spec/19-grammar.md +++ b/spec/19-grammar.md @@ -929,6 +929,9 @@ The grammar notation is described in [Grammars section](09-lexical-structure.md# : void <i id="grammar-type-declaration">type-declaration:</i> + ?<sub>opt</sub> <i><a href="#grammar-base-type-declaration">base-type-declaration</a></i> + +<i id="grammar-base-type-declaration">base-type-declaration:</i> array callable iterable

« previous php.standards.cvs (#389) next »