Skip to content
Open
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
14 changes: 14 additions & 0 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -7714,6 +7714,20 @@ ZEND_METHOD(ReflectionConstant, getName)
RETURN_STR_COPY(const_->name);
}

ZEND_METHOD(ReflectionConstant, inNamespace)
{
reflection_object *intern;
zend_constant *const_;

ZEND_PARSE_PARAMETERS_NONE();

GET_REFLECTION_OBJECT_PTR(const_);

const char *backslash = zend_memrchr(ZSTR_VAL(const_->name), '\\', ZSTR_LEN(const_->name));
RETURN_BOOL(backslash);
}
/* }}} */

ZEND_METHOD(ReflectionConstant, getNamespaceName)
{
reflection_object *intern;
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 @@ -912,6 +912,8 @@ public function __construct(string $name) {}

public function getName(): string {}

public function inNamespace(): bool {}

public function getNamespaceName(): string {}

public function getShortName(): string {}
Expand Down
6 changes: 5 additions & 1 deletion ext/reflection/php_reflection_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions ext/reflection/tests/ReflectionConstant_inNamespace.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
ReflectionConstant::inNamespace()
--FILE--
<?php

namespace Foo\Bar {
const NAMESPACED_CONST = 'in namespace';
}

namespace {
const GLOBAL_CONST = 'global';

$rc1 = new ReflectionConstant('GLOBAL_CONST');
var_dump($rc1->inNamespace());
var_dump($rc1->getNamespaceName());
var_dump($rc1->getShortName());

$rc2 = new ReflectionConstant('Foo\Bar\NAMESPACED_CONST');
var_dump($rc2->inNamespace());
var_dump($rc2->getNamespaceName());
var_dump($rc2->getShortName());

$rc3 = new ReflectionConstant('E_ERROR');
var_dump($rc3->inNamespace());
var_dump($rc3->getNamespaceName());
var_dump($rc3->getShortName());
}

?>
--EXPECT--
bool(false)
string(0) ""
string(12) "GLOBAL_CONST"
bool(true)
string(7) "Foo\Bar"
string(16) "NAMESPACED_CONST"
bool(false)
string(0) ""
string(7) "E_ERROR"
8 changes: 8 additions & 0 deletions ext/reflection/tests/ReflectionConstant_ns.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ namespace {
var_dump(new \ReflectionConstant('\\C'));
var_dump(new \ReflectionConstant('Foo\\C'));
var_dump(new \ReflectionConstant('\\Foo\\C'));
var_dump((new \ReflectionConstant('C'))->inNamespace());
var_dump((new \ReflectionConstant('\\C'))->inNamespace());
var_dump((new \ReflectionConstant('Foo\\C'))->inNamespace());
var_dump((new \ReflectionConstant('\\Foo\\C'))->inNamespace());
var_dump((new \ReflectionConstant('C'))->getNamespaceName());
var_dump((new \ReflectionConstant('\\C'))->getNamespaceName());
var_dump((new \ReflectionConstant('Foo\\C'))->getNamespaceName());
Expand Down Expand Up @@ -42,6 +46,10 @@ object(ReflectionConstant)#1 (1) {
["name"]=>
string(6) "\Foo\C"
}
bool(false)
bool(false)
bool(true)
bool(true)
string(0) ""
string(0) ""
string(3) "Foo"
Expand Down
Loading