1--TEST-- 2Union types in PHP 8.0 (nullable) 3--SKIPIF-- 4<?php if (PHP_VERSION_ID < 80000) die('skip PHP >= 8.0 only'); ?> 5--FILE-- 6<?php 7 8require __DIR__ . '/../util.php'; 9 10$code = <<<'PHP' 11<?php 12 13function test(?array $a, ?object $o) : ?\stdClass { 14 return null; 15} 16class X { 17 public ?array $arr; 18 public ?\ArrayObject $obj; 19} 20PHP; 21 22$node = ast\parse_code($code, $version=70); 23echo ast_dump($node), "\n"; 24--EXPECTF-- 25AST_STMT_LIST 26 0: AST_FUNC_DECL 27 flags: 0 28 name: "test" 29 docComment: null 30 params: AST_PARAM_LIST 31 0: AST_PARAM 32 flags: 0 33 type: AST_NULLABLE_TYPE 34 type: AST_TYPE 35 flags: TYPE_ARRAY (%d) 36 name: "a" 37 default: null 38 1: AST_PARAM 39 flags: 0 40 type: AST_NULLABLE_TYPE 41 type: AST_TYPE 42 flags: TYPE_OBJECT (%d) 43 name: "o" 44 default: null 45 stmts: AST_STMT_LIST 46 0: AST_RETURN 47 expr: AST_CONST 48 name: AST_NAME 49 flags: NAME_NOT_FQ (1) 50 name: "null" 51 returnType: AST_NULLABLE_TYPE 52 type: AST_NAME 53 flags: NAME_FQ (0) 54 name: "stdClass" 55 __declId: 0 56 1: AST_CLASS 57 flags: 0 58 name: "X" 59 docComment: null 60 extends: null 61 implements: null 62 stmts: AST_STMT_LIST 63 0: AST_PROP_GROUP 64 flags: MODIFIER_PUBLIC (1) 65 type: AST_NULLABLE_TYPE 66 type: AST_TYPE 67 flags: TYPE_ARRAY (%d) 68 props: AST_PROP_DECL 69 flags: 0 70 0: AST_PROP_ELEM 71 name: "arr" 72 default: null 73 docComment: null 74 1: AST_PROP_GROUP 75 flags: MODIFIER_PUBLIC (1) 76 type: AST_NULLABLE_TYPE 77 type: AST_NAME 78 flags: NAME_FQ (0) 79 name: "ArrayObject" 80 props: AST_PROP_DECL 81 flags: 0 82 0: AST_PROP_ELEM 83 name: "obj" 84 default: null 85 docComment: null 86 __declId: 1 87