mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
__PROPERTY__ does not work in all constant expression contexts
Fixes GH-17222 Closes GH-17378
This commit is contained in:
2
NEWS
2
NEWS
@@ -9,6 +9,8 @@ PHP NEWS
|
||||
with 0x0b). (nielsdos)
|
||||
. Fixed bug GH-16886 (ini_parse_quantity() fails to emit warning for 0x+0).
|
||||
(nielsdos)
|
||||
. Fixed bug GH-17222 (__PROPERTY__ magic constant does not work in all
|
||||
constant expression contexts). (ilutov)
|
||||
|
||||
- DOM:
|
||||
. Fixed bug GH-17397 (Assertion failure ext/dom/php_dom.c). (nielsdos)
|
||||
|
||||
45
Zend/tests/gh17222.phpt
Normal file
45
Zend/tests/gh17222.phpt
Normal file
@@ -0,0 +1,45 @@
|
||||
--TEST--
|
||||
GH-17222: __PROPERTY__ does not work in all constant expression contexts
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
#[Attribute]
|
||||
class MyAttribute {
|
||||
public function __construct(public string $msg) {}
|
||||
}
|
||||
|
||||
class Foo
|
||||
{
|
||||
#[MyAttr(msg: __PROPERTY__)]
|
||||
public string $i = __PROPERTY__ {
|
||||
#[MyAttr(msg: __PROPERTY__)]
|
||||
get {
|
||||
var_dump(__PROPERTY__);
|
||||
return $this->i;
|
||||
}
|
||||
set (#[MyAttr(msg: __PROPERTY__)] string $v) {
|
||||
$this->i = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$f = new Foo();
|
||||
var_dump($f->i);
|
||||
|
||||
$r = new ReflectionClass(Foo::class);
|
||||
$p = $r->getProperty('i');
|
||||
var_dump($p->getAttributes()[0]->getArguments()['msg']);
|
||||
|
||||
$get = $p->getHook(PropertyHookType::Get);
|
||||
var_dump($get->getAttributes()[0]->getArguments()['msg']);
|
||||
|
||||
$set = $p->getHook(PropertyHookType::Set);
|
||||
var_dump($set->getParameters()[0]->getAttributes()[0]->getArguments()['msg']);
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
string(1) "i"
|
||||
string(1) "i"
|
||||
string(1) "i"
|
||||
string(1) "i"
|
||||
string(1) "i"
|
||||
@@ -8634,6 +8634,13 @@ static void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast, uint32_t f
|
||||
zend_type type = ZEND_TYPE_INIT_NONE(0);
|
||||
flags |= zend_property_is_virtual(ce, name, hooks_ast, flags) ? ZEND_ACC_VIRTUAL : 0;
|
||||
|
||||
/* FIXME: This is a dirty fix to maintain ABI compatibility. We don't
|
||||
* have an actual property info yet, but we really only need the name
|
||||
* anyway. We should convert this to a zend_string. */
|
||||
ZEND_ASSERT(!CG(context).active_property_info);
|
||||
zend_property_info dummy_prop_info = { .name = name };
|
||||
CG(context).active_property_info = &dummy_prop_info;
|
||||
|
||||
if (!hooks_ast) {
|
||||
if (ce->ce_flags & ZEND_ACC_INTERFACE) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR,
|
||||
@@ -8726,6 +8733,8 @@ static void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast, uint32_t f
|
||||
if (attr_ast) {
|
||||
zend_compile_attributes(&info->attributes, attr_ast, 0, ZEND_ATTRIBUTE_TARGET_PROPERTY, 0);
|
||||
}
|
||||
|
||||
CG(context).active_property_info = NULL;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
Reference in New Issue
Block a user