Skip to content
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
20 changes: 20 additions & 0 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -7809,6 +7809,26 @@ ZEND_METHOD(ReflectionConstant, getShortName)
}
}

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

if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}

GET_REFLECTION_OBJECT_PTR(const_);

zend_type fake_type;
if (Z_TYPE(const_->value) == IS_OBJECT) {
fake_type = (zend_type) ZEND_TYPE_INIT_CLASS(Z_OBJCE(const_->value)->name, false, 0);
} else {
fake_type = (zend_type) ZEND_TYPE_INIT_CODE(Z_TYPE(const_->value), false, 0);
}
reflection_type_factory(fake_type, return_value, 1);
}

ZEND_METHOD(ReflectionConstant, getValue)
{
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 @@ -910,6 +910,8 @@ public function getNamespaceName(): string {}

public function getShortName(): string {}

public function getType(): ?ReflectionType {}

public function getValue(): mixed {}

public function isDeprecated(): bool {}
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.

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

const C_OBJ = new stdClass;
const C_NULL = null;
const C_BOOL = true;
const C_STRING = "string";
const C_ARRAY = ["a", "b", "c"];
const C_INT = 1234;
const C_FLOAT = 0.1234;
const C_OBJ2 = C_OBJ;

$list = [
"C_OBJ",
"C_NULL",
"C_BOOL",
"C_STRING",
"C_ARRAY",
"C_INT",
"C_FLOAT",
"C_OBJ2",
];

foreach ($list as $name) {
$rc = new ReflectionConstant($name);
echo $rc->getType(), "\n";
}

?>
--EXPECT--
stdClass
null
true
string
array
int
float
stdClass
Loading