Skip to content

Add a hasPrototype method to ReflectionMethod #8486

Closed
@ollieread

Description

@ollieread

Description

There currently exists a method, ReflectionMethod::getPrototype() to get a methods prototype. This method will throw an exception if one does not exist, but it provides no way to check if a method has a prototype.

Most other methods within the reflection extension that throw an exception for a get method also have a corresponding has method.

Without a hasPrototype method, developers need to use the exception to control application flow, which is an undesirable approach.

If my albeit limited understanding of the source is correct, the following within ext/reflection/php_reflection.c will achieve this.

ZEND_METHOD(ReflectionMethod, hasPrototype)
{
	reflection_object *intern;
	zend_function *mptr;

	GET_REFLECTION_OBJECT_PTR(mptr);

	if (zend_parse_parameters_none() == FAILURE) {
		RETURN_THROWS();
	}

        RETURN_BOOL(mptr->common.prototype != null);
}

I believe the following would also need to be done.

Update the stub ext/reflection/php_reflection.stub.php

/** @tentative-return-type */
public function hasPrototype(): bool {}

Update the arginfo ext/reflection/php_reflection_arginfo.h

ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_ReflectionMethod_hasPrototype, 0, 0, _IS_BOOL, 0)
ZEND_END_ARG_INFO()
//...
ZEND_METHOD(ReflectionMethod, hasPrototype);
//...
ZEND_ME(ReflectionMethod, hasPrototype, arginfo_class_ReflectionMethod_hasPrototype, ZEND_ACC_PUBLIC)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions