1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.4'

* PHP-8.4:
  __PROPERTY__ does not work in all constant expression contexts
This commit is contained in:
Ilija Tovilo
2025-01-13 16:43:32 +01:00
2 changed files with 54 additions and 0 deletions

45
Zend/tests/gh17222.phpt Normal file
View 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"

View File

@@ -8657,6 +8657,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,
@@ -8749,6 +8756,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;
}
}
/* }}} */