Skip to content

Commit

Permalink
Implement ReflectionClass::getModule
Browse files Browse the repository at this point in the history
Summary: We somehow missed ReflectionClass::getModule in our reflection API. This adds it.

Reviewed By: oulgen

Differential Revision: D40282577

fbshipit-source-id: 3a847de98c35fddc8b576515ef602b8a1f333090
  • Loading branch information
jamesjwu authored and facebook-github-bot committed Oct 12, 2022
1 parent 6d09f85 commit 90534fe
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions hphp/runtime/ext/reflection/ext_reflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,13 @@ static bool HHVM_METHOD(ReflectionClass, isInternalToModule) {
return cls->isInternal();
}

static Variant HHVM_METHOD(ReflectionClass, getModule) {
auto const cls = ReflectionClassHandle::GetClassFor(this_);
auto const name = cls->moduleName();
if (!name) return init_null_variant;
return String::attach(const_cast<StringData*>(name));
}

static bool HHVM_METHOD(ReflectionClass, isAbstract) {
auto const cls = ReflectionClassHandle::GetClassFor(this_);
return cls->attrs() & AttrAbstract;
Expand Down Expand Up @@ -2354,6 +2361,7 @@ struct ReflectionExtension final : Extension {
HHVM_ME(ReflectionClass, getInterfaceNames);
HHVM_ME(ReflectionClass, getRequirementNames);
HHVM_ME(ReflectionClass, getTraitNames);
HHVM_ME(ReflectionClass, getModule);

HHVM_ME(ReflectionClass, hasMethod);
HHVM_STATIC_ME(ReflectionClass, getMethodOrder);
Expand Down
8 changes: 8 additions & 0 deletions hphp/runtime/ext/reflection/ext_reflection_hni.php
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,14 @@ public function isFinal()[]: bool;
<<__Native>>
public function isInternalToModule()[]: bool;

/*
* Returns the module associated with the given function.
*
* @return ?string Returns the module name if the class is part of a module, null otherwise.
*/
<<__Native>>
public function getModule()[]: ?string;

/**
* ( excerpt from http://php.net/manual/en/reflectionclass.istrait.php )
*
Expand Down
1 change: 1 addition & 0 deletions hphp/test/slow/modules/reflection-1.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ function main() {
var_dump((new ReflectionFunction('f'))->getModule());
var_dump((new ReflectionFunction('g'))->getModule());
var_dump((new ReflectionMethod('C', 'f'))->getModule());
var_dump((new ReflectionClass('C'))->getModule());
}
1 change: 1 addition & 0 deletions hphp/test/slow/modules/reflection-1.php.expect
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
string(1) "A"
NULL
string(1) "B"
string(1) "B"

0 comments on commit 90534fe

Please sign in to comment.