Skip to content

Add ReflectionFunction::isAnonymous() #8499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,19 @@ ZEND_METHOD(ReflectionFunctionAbstract, isUserDefined)
}
/* }}} */

/* {{{ Returns whether this function is an anonymous closure or not */
ZEND_METHOD(ReflectionFunction, isAnonymous)
{
reflection_object *intern;
zend_function *fptr;

ZEND_PARSE_PARAMETERS_NONE();

GET_REFLECTION_OBJECT_PTR(fptr);
RETURN_BOOL((fptr->common.fn_flags & (ZEND_ACC_CLOSURE | ZEND_ACC_FAKE_CLOSURE)) == ZEND_ACC_CLOSURE);
}
/* }}} */

/* {{{ Returns whether this function has been disabled or not */
ZEND_METHOD(ReflectionFunction, isDisabled)
{
Expand Down
2 changes: 2 additions & 0 deletions ext/reflection/php_reflection.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ public function __construct(Closure|string $function) {}

public function __toString(): string {}

public function isAnonymous(): bool {}

/**
* @tentative-return-type
* @deprecated ReflectionFunction can no longer be constructed for disabled functions
Expand Down
6 changes: 5 additions & 1 deletion ext/reflection/php_reflection_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 62fcf63d2f3e93537560c3a03e71fda131a31586 */
* Stub hash: f06163b02a76ee7fa526e4662f015201e243743d */

ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_Reflection_getModifierNames, 0, 1, IS_ARRAY, 0)
ZEND_ARG_TYPE_INFO(0, modifiers, IS_LONG, 0)
Expand Down Expand Up @@ -91,6 +91,8 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ReflectionFunction___toString, 0, 0, IS_STRING, 0)
ZEND_END_ARG_INFO()

#define arginfo_class_ReflectionFunction_isAnonymous arginfo_class_ReflectionFunctionAbstract_hasTentativeReturnType

#define arginfo_class_ReflectionFunction_isDisabled arginfo_class_ReflectionFunctionAbstract_inNamespace

ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_ReflectionFunction_invoke, 0, 0, IS_MIXED, 0)
Expand Down Expand Up @@ -630,6 +632,7 @@ ZEND_METHOD(ReflectionFunctionAbstract, getTentativeReturnType);
ZEND_METHOD(ReflectionFunctionAbstract, getAttributes);
ZEND_METHOD(ReflectionFunction, __construct);
ZEND_METHOD(ReflectionFunction, __toString);
ZEND_METHOD(ReflectionFunction, isAnonymous);
ZEND_METHOD(ReflectionFunction, isDisabled);
ZEND_METHOD(ReflectionFunction, invoke);
ZEND_METHOD(ReflectionFunction, invokeArgs);
Expand Down Expand Up @@ -878,6 +881,7 @@ static const zend_function_entry class_ReflectionFunctionAbstract_methods[] = {
static const zend_function_entry class_ReflectionFunction_methods[] = {
ZEND_ME(ReflectionFunction, __construct, arginfo_class_ReflectionFunction___construct, ZEND_ACC_PUBLIC)
ZEND_ME(ReflectionFunction, __toString, arginfo_class_ReflectionFunction___toString, ZEND_ACC_PUBLIC)
ZEND_ME(ReflectionFunction, isAnonymous, arginfo_class_ReflectionFunction_isAnonymous, ZEND_ACC_PUBLIC)
ZEND_ME(ReflectionFunction, isDisabled, arginfo_class_ReflectionFunction_isDisabled, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED)
ZEND_ME(ReflectionFunction, invoke, arginfo_class_ReflectionFunction_invoke, ZEND_ACC_PUBLIC)
ZEND_ME(ReflectionFunction, invokeArgs, arginfo_class_ReflectionFunction_invokeArgs, ZEND_ACC_PUBLIC)
Expand Down
17 changes: 17 additions & 0 deletions ext/reflection/tests/ReflectionFunction_isAnonymous.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
ReflectionFunction::isAnonymous
--FILE--
<?php
$rf = new ReflectionFunction(function() {});
var_dump($rf->isAnonymous());

$rf = new ReflectionFunction('strlen');
var_dump($rf->isAnonymous());

$rf = new ReflectionFunction(strlen(...));
var_dump($rf->isAnonymous());
?>
--EXPECT--
bool(true)
bool(false)
bool(false)