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=50); 23echo ast_dump($node), "\n"; 24$node = ast\parse_code($code, $version=70); 25echo ast_dump($node), "\n"; 26--EXPECTF-- 27Deprecated: ast\parse_code(): Version 50 is deprecated in %s.php on line 17 28AST_STMT_LIST 29 0: AST_FUNC_DECL 30 name: "test" 31 docComment: null 32 params: AST_PARAM_LIST 33 0: AST_PARAM 34 type: AST_NULLABLE_TYPE 35 type: AST_TYPE 36 flags: TYPE_ARRAY (7) 37 name: "a" 38 default: null 39 1: AST_PARAM 40 type: AST_NULLABLE_TYPE 41 type: AST_TYPE 42 flags: TYPE_OBJECT (8) 43 name: "o" 44 default: null 45 uses: null 46 stmts: AST_STMT_LIST 47 0: AST_RETURN 48 expr: AST_CONST 49 name: AST_NAME 50 flags: NAME_NOT_FQ (1) 51 name: "null" 52 returnType: AST_NULLABLE_TYPE 53 type: AST_NAME 54 flags: NAME_FQ (0) 55 name: "stdClass" 56 __declId: 0 57 1: AST_CLASS 58 name: "X" 59 docComment: null 60 extends: null 61 implements: null 62 stmts: AST_STMT_LIST 63 0: AST_PROP_DECL 64 flags: MODIFIER_PUBLIC (1) 65 0: AST_PROP_ELEM 66 name: "arr" 67 default: null 68 docComment: null 69 1: AST_PROP_DECL 70 flags: MODIFIER_PUBLIC (1) 71 0: AST_PROP_ELEM 72 name: "obj" 73 default: null 74 docComment: null 75 __declId: 1 76AST_STMT_LIST 77 0: AST_FUNC_DECL 78 name: "test" 79 docComment: null 80 params: AST_PARAM_LIST 81 0: AST_PARAM 82 type: AST_NULLABLE_TYPE 83 type: AST_TYPE 84 flags: TYPE_ARRAY (7) 85 name: "a" 86 default: null 87 1: AST_PARAM 88 type: AST_NULLABLE_TYPE 89 type: AST_TYPE 90 flags: TYPE_OBJECT (8) 91 name: "o" 92 default: null 93 stmts: AST_STMT_LIST 94 0: AST_RETURN 95 expr: AST_CONST 96 name: AST_NAME 97 flags: NAME_NOT_FQ (1) 98 name: "null" 99 returnType: AST_NULLABLE_TYPE 100 type: AST_NAME 101 flags: NAME_FQ (0) 102 name: "stdClass" 103 __declId: 0 104 1: AST_CLASS 105 name: "X" 106 docComment: null 107 extends: null 108 implements: null 109 stmts: AST_STMT_LIST 110 0: AST_PROP_GROUP 111 flags: MODIFIER_PUBLIC (1) 112 type: AST_NULLABLE_TYPE 113 type: AST_TYPE 114 flags: TYPE_ARRAY (7) 115 props: AST_PROP_DECL 116 0: AST_PROP_ELEM 117 name: "arr" 118 default: null 119 docComment: null 120 1: AST_PROP_GROUP 121 flags: MODIFIER_PUBLIC (1) 122 type: AST_NULLABLE_TYPE 123 type: AST_NAME 124 flags: NAME_FQ (0) 125 name: "ArrayObject" 126 props: AST_PROP_DECL 127 0: AST_PROP_ELEM 128 name: "obj" 129 default: null 130 docComment: null 131 __declId: 1