1--TEST-- 2Property type hints in PHP 7.4 3--SKIPIF-- 4<?php if (PHP_VERSION_ID < 70400) die('skip PHP >= 7.4 only'); ?> 5--FILE-- 6<?php 7 8require __DIR__ . '/../util.php'; 9 10$code = <<<'PHP' 11<?php 12namespace Foo; 13class test { 14 public int $i = 2, $j; 15 public static ?string $s; 16 private ?iterable $it; 17 protected Row $row; 18 var \stdClass $o; 19 private static $normal = null; 20} 21PHP; 22 23$node = ast\parse_code($code, $version=60); 24echo "The type property should not be set in version 60\n"; 25echo ast_dump($node), "\n"; 26echo "But the type property should be set in version 70\n"; 27$node = ast\parse_code($code, $version=70); 28echo ast_dump($node), "\n"; 29?> 30--EXPECTF-- 31Deprecated: ast\parse_code(): Version 60 is deprecated in %s.php on line 18 32The type property should not be set in version 60 33AST_STMT_LIST 34 0: AST_NAMESPACE 35 name: "Foo" 36 stmts: null 37 1: AST_CLASS 38 name: "test" 39 docComment: null 40 extends: null 41 implements: null 42 stmts: AST_STMT_LIST 43 0: AST_PROP_DECL 44 flags: MODIFIER_PUBLIC (%d) 45 0: AST_PROP_ELEM 46 name: "i" 47 default: 2 48 docComment: null 49 1: AST_PROP_ELEM 50 name: "j" 51 default: null 52 docComment: null 53 1: AST_PROP_DECL 54 flags: MODIFIER_PUBLIC | MODIFIER_STATIC (%d) 55 0: AST_PROP_ELEM 56 name: "s" 57 default: null 58 docComment: null 59 2: AST_PROP_DECL 60 flags: MODIFIER_PRIVATE (%d) 61 0: AST_PROP_ELEM 62 name: "it" 63 default: null 64 docComment: null 65 3: AST_PROP_DECL 66 flags: MODIFIER_PROTECTED (%d) 67 0: AST_PROP_ELEM 68 name: "row" 69 default: null 70 docComment: null 71 4: AST_PROP_DECL 72 flags: MODIFIER_PUBLIC (%d) 73 0: AST_PROP_ELEM 74 name: "o" 75 default: null 76 docComment: null 77 5: AST_PROP_DECL 78 flags: MODIFIER_PRIVATE | MODIFIER_STATIC (%d) 79 0: AST_PROP_ELEM 80 name: "normal" 81 default: AST_CONST 82 name: AST_NAME 83 flags: NAME_NOT_FQ (1) 84 name: "null" 85 docComment: null 86 __declId: 0 87But the type property should be set in version 70 88AST_STMT_LIST 89 0: AST_NAMESPACE 90 name: "Foo" 91 stmts: null 92 1: AST_CLASS 93 name: "test" 94 docComment: null 95 extends: null 96 implements: null 97 stmts: AST_STMT_LIST 98 0: AST_PROP_GROUP 99 flags: MODIFIER_PUBLIC (%d) 100 type: AST_TYPE 101 flags: TYPE_LONG (4) 102 props: AST_PROP_DECL 103 0: AST_PROP_ELEM 104 name: "i" 105 default: 2 106 docComment: null 107 1: AST_PROP_ELEM 108 name: "j" 109 default: null 110 docComment: null 111 1: AST_PROP_GROUP 112 flags: MODIFIER_PUBLIC | MODIFIER_STATIC (%d) 113 type: AST_NULLABLE_TYPE 114 type: AST_TYPE 115 flags: TYPE_STRING (6) 116 props: AST_PROP_DECL 117 0: AST_PROP_ELEM 118 name: "s" 119 default: null 120 docComment: null 121 2: AST_PROP_GROUP 122 flags: MODIFIER_PRIVATE (%d) 123 type: AST_NULLABLE_TYPE 124 type: AST_TYPE 125 flags: TYPE_ITERABLE (%d) 126 props: AST_PROP_DECL 127 0: AST_PROP_ELEM 128 name: "it" 129 default: null 130 docComment: null 131 3: AST_PROP_GROUP 132 flags: MODIFIER_PROTECTED (%d) 133 type: AST_NAME 134 flags: NAME_NOT_FQ (1) 135 name: "Row" 136 props: AST_PROP_DECL 137 0: AST_PROP_ELEM 138 name: "row" 139 default: null 140 docComment: null 141 4: AST_PROP_GROUP 142 flags: MODIFIER_PUBLIC (%d) 143 type: AST_NAME 144 flags: NAME_FQ (0) 145 name: "stdClass" 146 props: AST_PROP_DECL 147 0: AST_PROP_ELEM 148 name: "o" 149 default: null 150 docComment: null 151 5: AST_PROP_GROUP 152 flags: MODIFIER_PRIVATE | MODIFIER_STATIC (%d) 153 type: null 154 props: AST_PROP_DECL 155 0: AST_PROP_ELEM 156 name: "normal" 157 default: AST_CONST 158 name: AST_NAME 159 flags: NAME_NOT_FQ (1) 160 name: "null" 161 docComment: null 162 __declId: 0 163