Skip to content

Commit b8d8a49

Browse files
committed
Add Reflection support for namespace visibility
Expose namespace-private visibility through Reflection API. Add methods to query whether a member has namespace-scoped visibility: * ReflectionMethod::isNamespacePrivate(): bool * ReflectionProperty::isNamespacePrivate(): bool * ReflectionProperty::isNamespacePrivateSet(): bool These methods check the ZEND_ACC_NAMESPACE_PRIVATE and ZEND_ACC_NAMESPACE_PRIVATE_SET flags respectively, allowing introspection of namespace-scoped visibility. Reflection bypasses namespace visibility checks (consistent with how it handles private members), but these methods provide full introspection capability.
1 parent 50eec2e commit b8d8a49

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

ext/reflection/php_reflection.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3558,6 +3558,13 @@ ZEND_METHOD(ReflectionMethod, isProtected)
35583558
}
35593559
/* }}} */
35603560

3561+
/* {{{ Returns whether this method is namespace-private */
3562+
ZEND_METHOD(ReflectionMethod, isNamespacePrivate)
3563+
{
3564+
_function_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_NAMESPACE_PRIVATE);
3565+
}
3566+
/* }}} */
3567+
35613568
/* {{{ Returns whether this function is deprecated */
35623569
ZEND_METHOD(ReflectionFunctionAbstract, isDeprecated)
35633570
{
@@ -5833,6 +5840,13 @@ ZEND_METHOD(ReflectionProperty, isProtected)
58335840
}
58345841
/* }}} */
58355842

5843+
/* {{{ Returns whether this property is namespace-private */
5844+
ZEND_METHOD(ReflectionProperty, isNamespacePrivate)
5845+
{
5846+
_property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_NAMESPACE_PRIVATE);
5847+
}
5848+
/* }}} */
5849+
58365850
ZEND_METHOD(ReflectionProperty, isPrivateSet)
58375851
{
58385852
_property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PRIVATE_SET);
@@ -5843,6 +5857,11 @@ ZEND_METHOD(ReflectionProperty, isProtectedSet)
58435857
_property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PROTECTED_SET);
58445858
}
58455859

5860+
ZEND_METHOD(ReflectionProperty, isNamespacePrivateSet)
5861+
{
5862+
_property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_NAMESPACE_PRIVATE_SET);
5863+
}
5864+
58465865
/* {{{ Returns whether this property is static */
58475866
ZEND_METHOD(ReflectionProperty, isStatic)
58485867
{

ext/reflection/php_reflection.stub.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ public function isPrivate(): bool {}
193193
/** @tentative-return-type */
194194
public function isProtected(): bool {}
195195

196+
public function isNamespacePrivate(): bool {}
197+
196198
/** @tentative-return-type */
197199
public function isAbstract(): bool {}
198200

@@ -513,10 +515,14 @@ public function isPrivate(): bool {}
513515
/** @tentative-return-type */
514516
public function isProtected(): bool {}
515517

518+
public function isNamespacePrivate(): bool {}
519+
516520
public function isPrivateSet(): bool {}
517521

518522
public function isProtectedSet(): bool {}
519523

524+
public function isNamespacePrivateSet(): bool {}
525+
520526
/** @tentative-return-type */
521527
public function isStatic(): bool {}
522528

ext/reflection/php_reflection_arginfo.h

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)