Skip to content

Commit 1c0ad9b

Browse files
committed
Set default_object_handlers when registering internal enum
1 parent 2a2e0e8 commit 1c0ad9b

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

Zend/tests/enum/gh20914-001.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Bug GH-20914: Internal enums can be cloned
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

Zend/tests/enum/gh20914-002.phpt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
--TEST--
2+
Bug GH-20914: Internal enums can be compared
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(false)
54+
bool(false)

Zend/zend_enum.c

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

531+
ce->default_object_handlers = &zend_enum_object_handlers;
532+
531533
return ce;
532534
}
533535

0 commit comments

Comments
 (0)