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
45 changes: 45 additions & 0 deletions Zend/tests/gh17222.phpt
Original file line number Diff line number Diff line change
@@ -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"
9 changes: 9 additions & 0 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}
/* }}} */
Expand Down
Loading