Skip to content

Commit 90534fe

Browse files
jamesjwufacebook-github-bot
authored andcommitted
Implement ReflectionClass::getModule
Summary: We somehow missed ReflectionClass::getModule in our reflection API. This adds it. Reviewed By: oulgen Differential Revision: D40282577 fbshipit-source-id: 3a847de98c35fddc8b576515ef602b8a1f333090
1 parent 6d09f85 commit 90534fe

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

hphp/runtime/ext/reflection/ext_reflection.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,13 @@ static bool HHVM_METHOD(ReflectionClass, isInternalToModule) {
12641264
return cls->isInternal();
12651265
}
12661266

1267+
static Variant HHVM_METHOD(ReflectionClass, getModule) {
1268+
auto const cls = ReflectionClassHandle::GetClassFor(this_);
1269+
auto const name = cls->moduleName();
1270+
if (!name) return init_null_variant;
1271+
return String::attach(const_cast<StringData*>(name));
1272+
}
1273+
12671274
static bool HHVM_METHOD(ReflectionClass, isAbstract) {
12681275
auto const cls = ReflectionClassHandle::GetClassFor(this_);
12691276
return cls->attrs() & AttrAbstract;
@@ -2354,6 +2361,7 @@ struct ReflectionExtension final : Extension {
23542361
HHVM_ME(ReflectionClass, getInterfaceNames);
23552362
HHVM_ME(ReflectionClass, getRequirementNames);
23562363
HHVM_ME(ReflectionClass, getTraitNames);
2364+
HHVM_ME(ReflectionClass, getModule);
23572365

23582366
HHVM_ME(ReflectionClass, hasMethod);
23592367
HHVM_STATIC_ME(ReflectionClass, getMethodOrder);

hphp/runtime/ext/reflection/ext_reflection_hni.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,14 @@ public function isFinal()[]: bool;
16441644
<<__Native>>
16451645
public function isInternalToModule()[]: bool;
16461646

1647+
/*
1648+
* Returns the module associated with the given function.
1649+
*
1650+
* @return ?string Returns the module name if the class is part of a module, null otherwise.
1651+
*/
1652+
<<__Native>>
1653+
public function getModule()[]: ?string;
1654+
16471655
/**
16481656
* ( excerpt from http://php.net/manual/en/reflectionclass.istrait.php )
16491657
*

hphp/test/slow/modules/reflection-1.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ function main() {
1414
var_dump((new ReflectionFunction('f'))->getModule());
1515
var_dump((new ReflectionFunction('g'))->getModule());
1616
var_dump((new ReflectionMethod('C', 'f'))->getModule());
17+
var_dump((new ReflectionClass('C'))->getModule());
1718
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
string(1) "A"
22
NULL
33
string(1) "B"
4+
string(1) "B"

0 commit comments

Comments
 (0)