Skip to content

Commit cc21f5e

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: NEWS Set default_object_handlers when registering internal enums
2 parents c80ac79 + b273fc7 commit cc21f5e

File tree

11 files changed

+137
-1
lines changed

11 files changed

+137
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ PHP NEWS
1111
function triggered by bailout in php_output_lock_error()). (timwolla)
1212
. Fix OSS-Fuzz #471533782 (Infinite loop in GC destructor fiber). (ilutov)
1313
. Fix OSS-Fuzz #472563272 (Borked block_pass JMP[N]Z optimization). (ilutov)
14+
. Fixed bug GH-GH-20914 (Internal enums can be cloned and compared). (Arnaud)
1415

1516
- MbString:
1617
. Fixed bug GH-20833 (mb_str_pad() divide by zero if padding string is
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
--TEST--
2+
Enum comparison (internal enum)
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
8+
$foo = ZendTestUnitEnum::Foo;
9+
$bar = ZendTestUnitEnum::Bar;
10+
11+
var_dump($foo === $foo);
12+
var_dump($foo == $foo);
13+
14+
var_dump($foo === $bar);
15+
var_dump($foo == $bar);
16+
17+
var_dump($bar === $foo);
18+
var_dump($bar == $foo);
19+
20+
var_dump($foo > $foo);
21+
var_dump($foo < $foo);
22+
var_dump($foo >= $foo);
23+
var_dump($foo <= $foo);
24+
25+
var_dump($foo > $bar);
26+
var_dump($foo < $bar);
27+
var_dump($foo >= $bar);
28+
var_dump($foo <= $bar);
29+
30+
var_dump($foo > true);
31+
var_dump($foo < true);
32+
var_dump($foo >= true);
33+
var_dump($foo <= true);
34+
35+
?>
36+
--EXPECT--
37+
bool(true)
38+
bool(true)
39+
bool(false)
40+
bool(false)
41+
bool(false)
42+
bool(false)
43+
bool(false)
44+
bool(false)
45+
bool(true)
46+
bool(true)
47+
bool(false)
48+
bool(false)
49+
bool(false)
50+
bool(false)
51+
bool(false)
52+
bool(false)
53+
bool(true)
54+
bool(true)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Enum implements (internal enum)
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
8+
var_dump(ZendTestUnitEnum::Foo instanceof _ZendTestInterface);
9+
var_dump(ZendTestEnumWithInterface::Foo instanceof _ZendTestInterface);
10+
11+
?>
12+
--EXPECT--
13+
bool(false)
14+
bool(true)

Zend/tests/enum/instanceof-backed-enum.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
--TEST--
22
Auto implement BackedEnum interface
3+
--EXTENSIONS--
4+
zend_test
35
--FILE--
46
<?php
57

@@ -13,8 +15,12 @@ enum Baz: int {
1315

1416
var_dump(Foo::Bar instanceof BackedEnum);
1517
var_dump(Baz::Qux instanceof BackedEnum);
18+
var_dump(ZendTestUnitEnum::Foo instanceof BackedEnum);
19+
var_dump(ZendTestIntEnum::Foo instanceof BackedEnum);
1620

1721
?>
1822
--EXPECT--
1923
bool(false)
2024
bool(true)
25+
bool(false)
26+
bool(true)

Zend/tests/enum/instanceof-unitenum.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
--TEST--
22
Auto implement UnitEnum interface
3+
--EXTENSIONS--
4+
zend_test
35
--FILE--
46
<?php
57

@@ -11,8 +13,10 @@ class Baz {}
1113

1214
var_dump(Foo::Bar instanceof UnitEnum);
1315
var_dump((new Baz()) instanceof UnitEnum);
16+
var_dump(ZendTestUnitEnum::Foo instanceof UnitEnum);
1417

1518
?>
1619
--EXPECT--
1720
bool(true)
1821
bool(false)
22+
bool(true)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Enum disallows cloning (internal enum)
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
8+
try {
9+
var_dump(clone ZendTestIntEnum::Foo);
10+
} catch (Error $e) {
11+
echo $e->getMessage() . "\n";
12+
}
13+
14+
?>
15+
--EXPECT--
16+
Trying to clone an uncloneable object of class ZendTestIntEnum
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Enum case disallows dynamic properties (internal enum)
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
8+
$bar = ZendTestUnitEnum::Bar;
9+
10+
try {
11+
$bar->baz = 'Baz';
12+
} catch (\Error $e) {
13+
echo $e->getMessage();
14+
}
15+
16+
?>
17+
--EXPECT--
18+
Cannot create dynamic property ZendTestUnitEnum::$baz

Zend/zend_enum.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,8 @@ ZEND_API zend_class_entry *zend_register_internal_enum(
529529
zend_class_implements(ce, 1, zend_ce_backed_enum);
530530
}
531531

532+
ce->default_object_handlers = &zend_enum_object_handlers;
533+
532534
return ce;
533535
}
534536

ext/zend_test/test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static zend_class_entry *zend_test_ns2_ns_foo_class;
7272
static zend_class_entry *zend_test_unit_enum;
7373
static zend_class_entry *zend_test_string_enum;
7474
static zend_class_entry *zend_test_int_enum;
75+
static zend_class_entry *zend_test_enum_with_interface;
7576
static zend_class_entry *zend_test_magic_call;
7677
static zend_object_handlers zend_test_class_handlers;
7778

@@ -1493,6 +1494,7 @@ PHP_MINIT_FUNCTION(zend_test)
14931494
zend_test_unit_enum = register_class_ZendTestUnitEnum();
14941495
zend_test_string_enum = register_class_ZendTestStringEnum();
14951496
zend_test_int_enum = register_class_ZendTestIntEnum();
1497+
zend_test_enum_with_interface = register_class_ZendTestEnumWithInterface(zend_test_interface);
14961498

14971499
zend_test_magic_call = register_class__ZendTestMagicCall();
14981500

ext/zend_test/test.stub.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ enum ZendTestIntEnum: int {
208208
case Baz = -1;
209209
}
210210

211+
enum ZendTestEnumWithInterface implements _ZendTestInterface {
212+
case Foo;
213+
case Bar;
214+
}
215+
211216
function zend_trigger_bailout(): never {}
212217

213218
function zend_test_array_return(): array {}

0 commit comments

Comments
 (0)