1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2025-01-22 05:41:23 +01:00

PHP 7.1: Add void+iterable support

In PHP 7 mode, these will now be represented as strings 'void'
and 'iterable'.
This commit is contained in:
Nikita Popov 2016-07-05 22:35:27 +02:00
parent 038e11da4b
commit 5044fce1ff
4 changed files with 18 additions and 9 deletions

View File

@ -364,7 +364,7 @@ parameter:
;
type:
name { $$ = $this->handleScalarTypes($1); }
name { $$ = $this->handleBuiltinTypes($1); }
| T_ARRAY { $$ = 'array'; }
| T_CALLABLE { $$ = 'callable'; }
;

View File

@ -1677,7 +1677,7 @@ class Php7 extends \PhpParser\ParserAbstract
}
protected function reduceRule221() {
$this->semValue = $this->handleScalarTypes($this->semStack[$this->stackPos-(1-1)]);
$this->semValue = $this->handleBuiltinTypes($this->semStack[$this->stackPos-(1-1)]);
}
protected function reduceRule222() {

View File

@ -481,12 +481,14 @@ abstract class ParserAbstract implements Parser
return $style;
}
protected function handleScalarTypes(Name $name) {
protected function handleBuiltinTypes(Name $name) {
$scalarTypes = [
'bool' => true,
'int' => true,
'float' => true,
'string' => true,
'bool' => true,
'int' => true,
'float' => true,
'string' => true,
'iterable' => true,
'void' => true,
];
if (!$name->isUnqualified()) {

View File

@ -1,7 +1,7 @@
Scalar type declarations
-----
<?php
function test(bool $a, Int $b, FLOAT $c, StRiNg $d) {}
function test(bool $a, Int $b, FLOAT $c, StRiNg $d, iterable $e) : void {}
-----
!!php7
array(
@ -37,8 +37,15 @@ array(
name: d
default: null
)
4: Param(
type: iterable
byRef: false
variadic: false
name: e
default: null
)
)
returnType: null
returnType: void
stmts: array(
)
)