mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00

The compiler compiles $value == true to ZEND_BOOL, which always returns true for objects (with the default cast_object handler). However, when compared to a statically unknown rhs $value == $true, the resulting opcode ZEND_IS_EQUAL would call the objects compare handler. The zend_objects_not_comparable() handler, which is installed for enums and other internal classes, blanketly returns false. This does not match the ZEND_BOOL semantics. Object to boolean comparison is now handled directly in zend_compare(), analogous to object to null comparison. It continuous to call the cast_object handler, but guarantees consistent behavior across ZEND_BOOL and ZEND_IS_EQUAL. Fixes GH-16954 Closes GH-17031
57 lines
777 B
PHP
57 lines
777 B
PHP
--TEST--
|
|
Enum comparison
|
|
--FILE--
|
|
<?php
|
|
|
|
enum Foo {
|
|
case Bar;
|
|
case Baz;
|
|
}
|
|
|
|
$bar = Foo::Bar;
|
|
$baz = Foo::Baz;
|
|
|
|
var_dump($bar === $bar);
|
|
var_dump($bar == $bar);
|
|
|
|
var_dump($bar === $baz);
|
|
var_dump($bar == $baz);
|
|
|
|
var_dump($baz === $bar);
|
|
var_dump($baz == $bar);
|
|
|
|
var_dump($bar > $bar);
|
|
var_dump($bar < $bar);
|
|
var_dump($bar >= $bar);
|
|
var_dump($bar <= $bar);
|
|
|
|
var_dump($bar > $baz);
|
|
var_dump($bar < $baz);
|
|
var_dump($bar >= $baz);
|
|
var_dump($bar <= $baz);
|
|
|
|
var_dump($bar > true);
|
|
var_dump($bar < true);
|
|
var_dump($bar >= true);
|
|
var_dump($bar <= true);
|
|
|
|
?>
|
|
--EXPECT--
|
|
bool(true)
|
|
bool(true)
|
|
bool(false)
|
|
bool(false)
|
|
bool(false)
|
|
bool(false)
|
|
bool(false)
|
|
bool(false)
|
|
bool(true)
|
|
bool(true)
|
|
bool(false)
|
|
bool(false)
|
|
bool(false)
|
|
bool(false)
|
|
bool(false)
|
|
bool(false)
|
|
bool(true)
|
|
bool(true)
|