File tree Expand file tree Collapse file tree 4 files changed +20
-8
lines changed Expand file tree Collapse file tree 4 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -10,10 +10,16 @@ var_dump('' is string);
10
10
var_dump('' is int);
11
11
var_dump('' is bool);
12
12
var_dump('' is object);
13
+ var_dump('' is ?string);
14
+ var_dump(null is ?string);
15
+ var_dump('' is ?object);
13
16
14
17
?>
15
18
--EXPECT--
16
19
bool(true)
17
20
bool(false)
18
21
bool(false)
19
22
bool(false)
23
+ bool(true)
24
+ bool(true)
25
+ bool(false)
Original file line number Diff line number Diff line change @@ -11,6 +11,13 @@ class Foo {
11
11
const FOO = 'foo ' ;
12
12
}
13
13
14
+ var_dump (match (null ) {
15
+ is false => wrong (),
16
+ is 0 => wrong (),
17
+ is [] => wrong (),
18
+ is null => 'Literal pattern with null ' ,
19
+ });
20
+
14
21
var_dump (match (true ) {
15
22
is false => wrong (),
16
23
is true => 'Literal pattern with bool ' ,
@@ -57,20 +64,14 @@ var_dump(match (15) {
57
64
is 20 .. < 30 => wrong (),
58
65
});
59
66
60
- // var_dump(match (true) {
61
- // false if false => wrong(),
62
- // false if true => wrong(),
63
- // true if false => wrong(),
64
- // true if true => 'Guard',
65
- // });
66
-
67
67
// var_dump(match ('foo') {
68
68
// is 'bar' => wrong(),
69
69
// is Foo::FOO => 'Class constant literal',
70
70
// });
71
71
72
72
?>
73
73
--EXPECT--
74
+ string(25) "Literal pattern with null"
74
75
string(25) "Literal pattern with bool"
75
76
string(24) "Literal pattern with int"
76
77
string(27) "Literal pattern with string"
Original file line number Diff line number Diff line change @@ -6124,7 +6124,12 @@ static void zend_compile_type_pattern(zend_ast **ast_ptr)
6124
6124
{
6125
6125
zend_ast * type_pattern_ast = * ast_ptr ;
6126
6126
zend_ast * type_ast = type_pattern_ast -> child [0 ];
6127
+ bool nullable = type_ast -> attr & ZEND_TYPE_NULLABLE ;
6128
+ type_ast -> attr &= ~ZEND_TYPE_NULLABLE ;
6127
6129
zend_type type = zend_compile_single_typename (type_ast );
6130
+ if (nullable ) {
6131
+ ZEND_TYPE_FULL_MASK (type ) |= MAY_BE_NULL ;
6132
+ }
6128
6133
uint32_t type_mask = ZEND_TYPE_PURE_MASK (type );
6129
6134
6130
6135
// FIXME: Make sure the type mask actually fits
Original file line number Diff line number Diff line change @@ -1302,7 +1302,7 @@ compound_pattern:
1302
1302
1303
1303
type_pattern :
1304
1304
type_without_static { $$ = zend_ast_create(ZEND_AST_TYPE_PATTERN, $1 ); }
1305
- | ' ?' type_without_static { $$ = zend_ast_create(ZEND_AST_TYPE_PATTERN, $2 ); $$ ->attr |= ZEND_TYPE_NULLABLE; }
1305
+ | ' ?' type_without_static { $$ = zend_ast_create(ZEND_AST_TYPE_PATTERN, $2 ); $2 ->attr |= ZEND_TYPE_NULLABLE; }
1306
1306
;
1307
1307
1308
1308
scalar_pattern :
You can’t perform that action at this time.
0 commit comments