diff --git a/src/BSON/Persistable.c b/src/BSON/Persistable.c index c6cab6928..91003ffa1 100644 --- a/src/BSON/Persistable.c +++ b/src/BSON/Persistable.c @@ -21,18 +21,7 @@ zend_class_entry* php_phongo_persistable_ce; -static int php_phongo_implement_persistable(zend_class_entry* interface, zend_class_entry* class_type) -{ - if (class_type->ce_flags & ZEND_ACC_ENUM) { - zend_error_noreturn(E_ERROR, "Enum class %s cannot implement interface %s", ZSTR_VAL(class_type->name), ZSTR_VAL(interface->name)); - return FAILURE; - } - - return SUCCESS; -} - void php_phongo_persistable_init_ce(INIT_FUNC_ARGS) { - php_phongo_persistable_ce = register_class_MongoDB_BSON_Persistable(php_phongo_serializable_ce, php_phongo_unserializable_ce); - php_phongo_persistable_ce->interface_gets_implemented = php_phongo_implement_persistable; + php_phongo_persistable_ce = register_class_MongoDB_BSON_Persistable(php_phongo_serializable_ce, php_phongo_unserializable_ce); } diff --git a/src/BSON/Unserializable.c b/src/BSON/Unserializable.c index 4ce30684c..33bfefc72 100644 --- a/src/BSON/Unserializable.c +++ b/src/BSON/Unserializable.c @@ -24,7 +24,15 @@ zend_class_entry* php_phongo_unserializable_ce; static int php_phongo_implement_unserializable(zend_class_entry* interface, zend_class_entry* class_type) { if (class_type->ce_flags & ZEND_ACC_ENUM) { - zend_error_noreturn(E_ERROR, "Enum class %s cannot implement interface %s", ZSTR_VAL(class_type->name), ZSTR_VAL(interface->name)); + zend_class_entry* error_interface = interface; + + /* Persistable extends Unserializable, so this handler may be called for + * Persistable enums; prefer Persistable in the fatal message when applicable. */ + if (interface == php_phongo_unserializable_ce && php_phongo_persistable_ce && instanceof_function(class_type, php_phongo_persistable_ce)) { + error_interface = php_phongo_persistable_ce; + } + + zend_error_noreturn(E_ERROR, "Enum class %s cannot implement interface %s", ZSTR_VAL(class_type->name), ZSTR_VAL(error_interface->name)); return FAILURE; } diff --git a/tests/bson/bson-enum_error-003.phpt b/tests/bson/bson-enum_error-003.phpt index e78f766fa..788868437 100644 --- a/tests/bson/bson-enum_error-003.phpt +++ b/tests/bson/bson-enum_error-003.phpt @@ -15,5 +15,5 @@ enum MyEnum implements MongoDB\BSON\Persistable ?> ===DONE=== ---EXPECTREGEX-- -Fatal error: Enum class MyEnum cannot implement interface MongoDB\\BSON\\(Persistable|Unserializable) in .+ on line \d+ +--EXPECTF-- +Fatal error: Enum class MyEnum cannot implement interface MongoDB\BSON\Persistable in %s on line %d diff --git a/tests/bson/bson-enum_error-004.phpt b/tests/bson/bson-enum_error-004.phpt index 32a43d568..3136f0060 100644 --- a/tests/bson/bson-enum_error-004.phpt +++ b/tests/bson/bson-enum_error-004.phpt @@ -15,5 +15,5 @@ enum MyBackedEnum: int implements MongoDB\BSON\Persistable ?> ===DONE=== ---EXPECTREGEX-- -Fatal error: Enum class MyBackedEnum cannot implement interface MongoDB\\BSON\\(Persistable|Unserializable) in .+ on line \d+ +--EXPECTF-- +Fatal error: Enum class MyBackedEnum cannot implement interface MongoDB\BSON\Persistable in %s on line %d