Skip to content

Commit f29bc08

Browse files
authored
reflection: Remove _DO_THROW() macro (#21399)
This is an unnecessary layer of indirection that hides the exception type and does not exist elsewhere (in a similar way).
1 parent f93b170 commit f29bc08

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

ext/reflection/php_reflection.c

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ PHPAPI zend_class_entry *reflection_fiber_ptr;
106106
PHPAPI zend_class_entry *reflection_constant_ptr;
107107
PHPAPI zend_class_entry *reflection_property_hook_type_ptr;
108108

109-
/* Exception throwing macro */
110-
#define _DO_THROW(msg) \
111-
zend_throw_exception(reflection_exception_ptr, msg, 0);
112-
113109
#define GET_REFLECTION_OBJECT() do { \
114110
intern = Z_REFLECTION_P(ZEND_THIS); \
115111
if (intern->ptr == NULL) { \
@@ -1658,7 +1654,7 @@ static zend_result get_parameter_default(zval *result, parameter_reference *para
16581654
ZEND_METHOD(ReflectionClass, __clone)
16591655
{
16601656
/* __clone() is private but this is reachable with reflection */
1661-
_DO_THROW("Cannot clone object using __clone()");
1657+
zend_throw_exception(reflection_exception_ptr, "Cannot clone object using __clone()", 0);
16621658
}
16631659
/* }}} */
16641660

@@ -2325,7 +2321,7 @@ ZEND_METHOD(ReflectionGenerator, __construct)
23252321

23262322
#define REFLECTION_CHECK_VALID_GENERATOR(ex) \
23272323
if (!ex) { \
2328-
_DO_THROW("Cannot fetch information from a closed Generator"); \
2324+
zend_throw_exception(reflection_exception_ptr, "Cannot fetch information from a closed Generator", 0); \
23292325
RETURN_THROWS(); \
23302326
}
23312327

@@ -2505,7 +2501,7 @@ ZEND_METHOD(ReflectionParameter, __construct)
25052501
if (((classref = zend_hash_index_find(Z_ARRVAL_P(reference), 0)) == NULL)
25062502
|| ((method = zend_hash_index_find(Z_ARRVAL_P(reference), 1)) == NULL))
25072503
{
2508-
_DO_THROW("Expected array($object, $method) or array($classname, $method)");
2504+
zend_throw_exception(reflection_exception_ptr, "Expected array($object, $method) or array($classname, $method)", 0);
25092505
RETURN_THROWS();
25102506
}
25112507

@@ -2587,7 +2583,7 @@ ZEND_METHOD(ReflectionParameter, __construct)
25872583
}
25882584
}
25892585
if (position == -1) {
2590-
_DO_THROW("The parameter specified by its name could not be found");
2586+
zend_throw_exception(reflection_exception_ptr, "The parameter specified by its name could not be found", 0);
25912587
goto failure;
25922588
}
25932589
} else {
@@ -2596,7 +2592,7 @@ ZEND_METHOD(ReflectionParameter, __construct)
25962592
goto failure;
25972593
}
25982594
if (position >= num_args) {
2599-
_DO_THROW("The parameter specified by its offset could not be found");
2595+
zend_throw_exception(reflection_exception_ptr, "The parameter specified by its offset could not be found", 0);
26002596
goto failure;
26012597
}
26022598
}
@@ -3370,7 +3366,7 @@ ZEND_METHOD(ReflectionMethod, getClosure)
33703366
}
33713367

33723368
if (!instanceof_function(Z_OBJCE_P(obj), mptr->common.scope)) {
3373-
_DO_THROW("Given object is not an instance of the class this method was declared in");
3369+
zend_throw_exception(reflection_exception_ptr, "Given object is not an instance of the class this method was declared in", 0);
33743370
RETURN_THROWS();
33753371
}
33763372

@@ -3440,7 +3436,7 @@ static void reflection_method_invoke(INTERNAL_FUNCTION_PARAMETERS, int variadic)
34403436
if (!variadic) {
34413437
efree(params);
34423438
}
3443-
_DO_THROW("Given object is not an instance of the class this method was declared in");
3439+
zend_throw_exception(reflection_exception_ptr, "Given object is not an instance of the class this method was declared in", 0);
34443440
RETURN_THROWS();
34453441
}
34463442

@@ -3456,7 +3452,7 @@ static void reflection_method_invoke(INTERNAL_FUNCTION_PARAMETERS, int variadic)
34563452
if (!variadic) {
34573453
efree(params);
34583454
}
3459-
_DO_THROW("Given Closure is not the same as the reflected Closure");
3455+
zend_throw_exception(reflection_exception_ptr, "Given Closure is not the same as the reflected Closure", 0);
34603456
RETURN_THROWS();
34613457
}
34623458
}
@@ -5904,7 +5900,7 @@ ZEND_METHOD(ReflectionProperty, getValue)
59045900

59055901
/* TODO: Should this always use intern->ce? */
59065902
if (!instanceof_function(Z_OBJCE_P(object), ref->prop ? ref->prop->ce : intern->ce)) {
5907-
_DO_THROW("Given object is not an instance of the class this property was declared in");
5903+
zend_throw_exception(reflection_exception_ptr, "Given object is not an instance of the class this property was declared in", 0);
59085904
RETURN_THROWS();
59095905
}
59105906

@@ -6012,7 +6008,7 @@ ZEND_METHOD(ReflectionProperty, getRawValue)
60126008
GET_REFLECTION_OBJECT_PTR(ref);
60136009

60146010
if (!instanceof_function(Z_OBJCE_P(object), intern->ce)) {
6015-
_DO_THROW("Given object is not an instance of the class this property was declared in");
6011+
zend_throw_exception(reflection_exception_ptr, "Given object is not an instance of the class this property was declared in", 0);
60166012
RETURN_THROWS();
60176013
}
60186014

@@ -6031,7 +6027,7 @@ ZEND_METHOD(ReflectionProperty, getRawValue)
60316027
intern->ce, Z_OBJ_P(object));
60326028

60336029
if (UNEXPECTED(prop && (prop->flags & ZEND_ACC_STATIC))) {
6034-
_DO_THROW("May not use getRawValue on static properties");
6030+
zend_throw_exception(reflection_exception_ptr, "May not use getRawValue on static properties", 0);
60356031
RETURN_THROWS();
60366032
}
60376033

@@ -6091,7 +6087,7 @@ ZEND_METHOD(ReflectionProperty, setRawValue)
60916087
intern->ce, Z_OBJ_P(object));
60926088

60936089
if (UNEXPECTED(prop && (prop->flags & ZEND_ACC_STATIC))) {
6094-
_DO_THROW("May not use setRawValue on static properties");
6090+
zend_throw_exception(reflection_exception_ptr, "May not use setRawValue on static properties", 0);
60956091
RETURN_THROWS();
60966092
}
60976093

@@ -6295,7 +6291,7 @@ ZEND_METHOD(ReflectionProperty, isInitialized)
62956291

62966292
/* TODO: Should this always use intern->ce? */
62976293
if (!instanceof_function(Z_OBJCE_P(object), ref->prop ? ref->prop->ce : intern->ce)) {
6298-
_DO_THROW("Given object is not an instance of the class this property was declared in");
6294+
zend_throw_exception(reflection_exception_ptr, "Given object is not an instance of the class this property was declared in", 0);
62996295
RETURN_THROWS();
63006296
}
63016297

@@ -6683,11 +6679,11 @@ ZEND_METHOD(ReflectionProperty, isReadable)
66836679
zend_property_info *prop = ref->prop;
66846680
if (prop && obj) {
66856681
if (prop->flags & ZEND_ACC_STATIC) {
6686-
_DO_THROW("null is expected as object argument for static properties");
6682+
zend_throw_exception(reflection_exception_ptr, "null is expected as object argument for static properties", 0);
66876683
RETURN_THROWS();
66886684
}
66896685
if (!instanceof_function(obj->ce, prop->ce)) {
6690-
_DO_THROW("Given object is not an instance of the class this property was declared in");
6686+
zend_throw_exception(reflection_exception_ptr, "Given object is not an instance of the class this property was declared in", 0);
66916687
RETURN_THROWS();
66926688
}
66936689
prop = reflection_property_get_effective_prop(ref, intern->ce, obj);
@@ -6789,11 +6785,11 @@ ZEND_METHOD(ReflectionProperty, isWritable)
67896785
zend_property_info *prop = ref->prop;
67906786
if (prop && obj) {
67916787
if (prop->flags & ZEND_ACC_STATIC) {
6792-
_DO_THROW("null is expected as object argument for static properties");
6788+
zend_throw_exception(reflection_exception_ptr, "null is expected as object argument for static properties", 0);
67936789
RETURN_THROWS();
67946790
}
67956791
if (!instanceof_function(obj->ce, prop->ce)) {
6796-
_DO_THROW("Given object is not an instance of the class this property was declared in");
6792+
zend_throw_exception(reflection_exception_ptr, "Given object is not an instance of the class this property was declared in", 0);
67976793
RETURN_THROWS();
67986794
}
67996795
prop = reflection_property_get_effective_prop(ref, intern->ce, obj);
@@ -7293,10 +7289,9 @@ ZEND_METHOD(ReflectionZendExtension, getCopyright)
72937289
/* {{{ Dummy constructor -- always throws ReflectionExceptions. */
72947290
ZEND_METHOD(ReflectionReference, __construct)
72957291
{
7296-
_DO_THROW(
7292+
zend_throw_exception(reflection_exception_ptr,
72977293
"Cannot directly instantiate ReflectionReference. "
7298-
"Use ReflectionReference::fromArrayElement() instead"
7299-
);
7294+
"Use ReflectionReference::fromArrayElement() instead", 0);
73007295
}
73017296
/* }}} */
73027297

@@ -7331,7 +7326,7 @@ ZEND_METHOD(ReflectionReference, fromArrayElement)
73317326
}
73327327

73337328
if (!item) {
7334-
_DO_THROW("Array key not found");
7329+
zend_throw_exception(reflection_exception_ptr, "Array key not found", 0);
73357330
RETURN_THROWS();
73367331
}
73377332

@@ -7358,7 +7353,7 @@ ZEND_METHOD(ReflectionReference, getId)
73587353

73597354
intern = Z_REFLECTION_P(ZEND_THIS);
73607355
if (Z_TYPE(intern->obj) != IS_REFERENCE) {
7361-
_DO_THROW("Corrupted ReflectionReference object");
7356+
zend_throw_exception(reflection_exception_ptr, "Corrupted ReflectionReference object", 0);
73627357
RETURN_THROWS();
73637358
}
73647359

@@ -7382,13 +7377,13 @@ ZEND_METHOD(ReflectionReference, getId)
73827377

73837378
ZEND_METHOD(ReflectionAttribute, __construct)
73847379
{
7385-
_DO_THROW("Cannot directly instantiate ReflectionAttribute");
7380+
zend_throw_exception(reflection_exception_ptr, "Cannot directly instantiate ReflectionAttribute", 0);
73867381
}
73877382

73887383
ZEND_METHOD(ReflectionAttribute, __clone)
73897384
{
73907385
/* __clone() is private but this is reachable with reflection */
7391-
_DO_THROW("Cannot clone object using __clone()");
7386+
zend_throw_exception(reflection_exception_ptr, "Cannot clone object using __clone()", 0);
73927387
}
73937388

73947389
/* {{{ Returns a string representation */

0 commit comments

Comments
 (0)