Skip to content

Commit 9c0b48e

Browse files
start delayed target validation
1 parent db55d8f commit 9c0b48e

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

custom_cast.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,25 +267,22 @@ static zend_result custom_cast_do_cast(
267267
/**
268268
* Ensure that the flags for a class entry correspond to a userland class
269269
*/
270-
static void require_user_class(uint32_t flags) {
270+
static const char* require_user_class(uint32_t flags) {
271271
// Must actually be on a class
272272
if (flags & ZEND_ACC_ENUM) {
273-
zend_error_noreturn(E_ERROR, "Cannot apply #[CustomCasting\\CustomCastable] to enum");
273+
return "Cannot apply #[CustomCasting\\CustomCastable] to enum";
274274
}
275275
if (flags & ZEND_ACC_INTERFACE) {
276-
zend_error_noreturn(E_ERROR, "Cannot apply #[CustomCasting\\CustomCastable] to interface");
276+
return "Cannot apply #[CustomCasting\\CustomCastable] to interface";
277277
}
278278
if (flags & ZEND_ACC_TRAIT) {
279-
zend_error_noreturn(E_ERROR, "Cannot apply #[CustomCasting\\CustomCastable] to trait");
279+
return "Cannot apply #[CustomCasting\\CustomCastable] to trait";
280280
}
281281
// Use ce->type != ZEND_INTERNAL_CLASS
282282
if (flags & ZEND_ACC_LINKED) {
283-
zend_error_noreturn(
284-
E_ERROR,
285-
"#[CustomCasting\\CustomCastable] is for user classes, internal classes can set a custom cast handler"
286-
);
283+
return "#[CustomCasting\\CustomCastable] is for user classes, internal classes can set a custom cast handler";
287284
}
288-
285+
return NULL;
289286
}
290287

291288
/**
@@ -381,7 +378,10 @@ static void ensure_class_has_interface(zend_class_entry *scope) {
381378
static void validate_custom_castable(
382379
zend_attribute *attr, uint32_t target, zend_class_entry *scope)
383380
{
384-
require_user_class(scope->ce_flags);
381+
const char *error = require_user_class(scope->ce_flags);
382+
if (error != NULL) {
383+
zend_error_noreturn(E_ERROR, error);
384+
}
385385
ensure_class_has_interface(scope);
386386
scope->default_object_handlers = &custom_cast_obj_handlers;
387387
}

0 commit comments

Comments
 (0)