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
18 changes: 18 additions & 0 deletions Zend/tests/property_hooks/abstract_get_only_readonly.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Readonly property satisfies get-only abstract property
--FILE--
<?php
abstract class A {
public abstract int $prop { get; }
}
class C extends A {
public readonly int $prop;
public function __construct(int $prop) {
$this->prop = $prop;
}
}
$c = new C(42);
var_dump($c->prop);
?>
--EXPECT--
int(42)
13 changes: 8 additions & 5 deletions Zend/tests/property_hooks/abstract_get_set_readonly.phpt
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
--TEST--
readonly property does not satisfy get/set abstract property
Readonly property cannot implement set hook of get/set abstract property
--FILE--
<?php
abstract class P {
abstract class A {
protected abstract int $prop { get; set; }
}
class C extends P {
public function __construct(protected readonly int $prop) {}
class C extends A {
protected readonly int $prop;
public function __construct(int $prop) {
$this->prop = $prop;
}
}
?>
--EXPECTF--
Fatal error: Class C contains 1 abstract method and must therefore be declared abstract or implement the remaining method (P::$prop::set) in %s on line %d
Fatal error: Readonly property C::$prop cannot implement set hook required by class A::$prop in %s on line %d
13 changes: 13 additions & 0 deletions Zend/tests/property_hooks/abstract_get_set_readonly_promoted.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Readonly promoted property cannot implement set hook of get/set abstract property
--FILE--
<?php
abstract class A {
protected abstract int $prop { get; set; }
}
class C extends A {
public function __construct(protected readonly int $prop) {}
}
?>
--EXPECTF--
Fatal error: Readonly property C::$prop cannot implement set hook required by class A::$prop in %s on line %d
16 changes: 16 additions & 0 deletions Zend/tests/property_hooks/abstract_get_set_readonly_public.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Readonly property cannot implement set hook of public get/set abstract property
--FILE--
<?php
abstract class A {
public abstract int $prop { get; set; }
}
class C extends A {
public readonly int $prop;
public function __construct(int $prop) {
$this->prop = $prop;
}
}
?>
--EXPECTF--
Fatal error: Readonly property C::$prop cannot implement set hook required by class A::$prop in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Readonly promoted property cannot implement set hook of public get/set abstract property
--FILE--
<?php
abstract class A {
public abstract int $prop { get; set; }
}
class C extends A {
public function __construct(public readonly int $prop) {}
}
?>
--EXPECTF--
Fatal error: Readonly property C::$prop cannot implement set hook required by class A::$prop in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Readonly public(set) property cannot implement set hook of public get/set abstract property
--FILE--
<?php
abstract class A {
public abstract int $prop { get; set; }
}
class C extends A {
public public(set) readonly int $prop;
public function __construct(int $prop) {
$this->prop = $prop;
}
}
?>
--EXPECTF--
Fatal error: Readonly property C::$prop cannot implement set hook required by class A::$prop in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Readonly promoted public(set) property cannot implement set hook of public get/set abstract property
--FILE--
<?php
abstract class A {
public abstract int $prop { get; set; }
}
class C extends A {
public function __construct(public public(set) readonly int $prop) {}
}
?>
--EXPECTF--
Fatal error: Readonly property C::$prop cannot implement set hook required by class A::$prop in %s on line %d
15 changes: 0 additions & 15 deletions Zend/tests/property_hooks/interface_get_set_readonly.phpt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
readonly property satisfies get only interface property
Readonly property satisfies get-only interface property
--FILE--
<?php
interface I {
Expand Down
16 changes: 16 additions & 0 deletions Zend/tests/property_hooks/interface_readonly_get_set.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Readonly property cannot implement set hook of get/set interface property
--FILE--
<?php
interface I {
public int $prop { get; set; }
}
class C implements I {
public readonly int $prop;
public function __construct(int $prop) {
$this->prop = $prop;
}
}
?>
--EXPECTF--
Fatal error: Readonly property C::$prop cannot implement set hook required by interface I::$prop in %s on line %d
13 changes: 13 additions & 0 deletions Zend/tests/property_hooks/interface_readonly_get_set_promoted.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Readonly promoted property cannot implement set hook of get/set interface property
--FILE--
<?php
interface I {
public int $prop { get; set; }
}
class C implements I {
public function __construct(public readonly int $prop) {}
}
?>
--EXPECTF--
Fatal error: Readonly property C::$prop cannot implement set hook required by interface I::$prop in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Readonly public(set) property cannot implement set hook of get/set interface property
--FILE--
<?php
interface I {
public int $prop { get; set; }
}
class C implements I {
public public(set) readonly int $prop;
public function __construct(int $prop) {
$this->prop = $prop;
}
}
?>
--EXPECTF--
Fatal error: Readonly property C::$prop cannot implement set hook required by interface I::$prop in %s on line %d
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Readonly promoted public(set) property cannot implement set hook of get/set interface property
--FILE--
<?php
interface I {
public int $prop { get; set; }
}
class C implements I {
public function __construct(public public(set) readonly int $prop) {}
}
?>
--EXPECTF--
Fatal error: Readonly property C::$prop cannot implement set hook required by interface I::$prop in %s on line %d
14 changes: 14 additions & 0 deletions Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,20 @@ static void do_inherit_property(zend_property_info *parent_info, zend_string *ke
ZSTR_VAL(ce->name), ZSTR_VAL(key));
}
}
if (parent_info->hooks
&& parent_info->hooks[ZEND_PROPERTY_HOOK_SET]
&& parent_info->hooks[ZEND_PROPERTY_HOOK_SET]->common.fn_flags & ZEND_ACC_ABSTRACT
&& child_info->flags & ZEND_ACC_READONLY
&& !property_has_operation(child_info, ZEND_PROPERTY_HOOK_SET)) {
zend_error_noreturn(
E_COMPILE_ERROR,
"Readonly property %s::$%s cannot implement set hook required by %s %s::$%s",
ZSTR_VAL(ce->name),
ZSTR_VAL(key),
zend_get_object_type_case(parent_info->ce, false),
ZSTR_VAL(parent_info->ce->name),
ZSTR_VAL(key));
}
if (UNEXPECTED((child_info->flags & ZEND_ACC_PPP_SET_MASK))
/* Get-only virtual properties have no set visibility, so any child visibility is fine. */
&& !(parent_info->hooks && (parent_info->flags & ZEND_ACC_VIRTUAL) && !parent_info->hooks[ZEND_PROPERTY_HOOK_SET])) {
Expand Down
Loading