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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ PHP NEWS
- Reflection:
. Fix trampoline leak when object construction fails for lazy object.
(ndossche)
. Fixed ReflectionClassConstant::getValue() reading a reference as the name
of the constant in the error raised for a typed constant. (Nicolas Grekas)

- SAPI:
. Fixed infinite loop in sapi_header_op() for headers of 4 GiB or more.
Expand Down
3 changes: 3 additions & 0 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -4143,6 +4143,9 @@ ZEND_METHOD(ReflectionClassConstant, getValue)
RETURN_THROWS();
}

ZVAL_DEREF(name);
ZEND_ASSERT(Z_TYPE_P(name) == IS_STRING);

if (Z_TYPE(ref->value) == IS_CONSTANT_AST) {
zend_result result = zend_update_class_constant(ref, Z_STR_P(name), ref->ce);
if (result == FAILURE) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
ReflectionClassConstant::getValue() after taking a reference to the name property
--FILE--
<?php

define('RUNTIME_VALUE', 'abc');

class Test {
public const int C = RUNTIME_VALUE;
}

$rc = new ReflectionClassConstant(Test::class, 'C');
$name = &$rc->name;
try {
var_dump($rc->getValue());
} catch (Throwable $e) {
echo $e::class, ": ", $e->getMessage(), "\n";
}

?>
--EXPECT--
TypeError: Cannot assign string to class constant Test::C of type int
Loading