Skip to content

[RFC] Allow hooks for backed readonly properties #18757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor: improved misleading error handling
  • Loading branch information
NickSdot committed Jun 14, 2025
commit 92d70bcd6af0908d24a92e0947c50d4df0b6c4f2
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ readonly class Test {

?>
--EXPECTF--
Fatal error: Hooked virtual properties cannot be readonly in %s on line %d
Fatal error: Hooked virtual properties may not be declared readonly in %s on line %d
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Virtual readonly property in interface throws
Hooked properties in abstract classes cannot be readonly
--FILE--
<?php

Expand All @@ -8,4 +8,4 @@ abstract class Test {
}
?>
--EXPECTF--
Fatal error: Hooked virtual properties cannot be readonly in %s on line %d
Fatal error: Hooked properties in abstract classes may not be declared readonly in %s on line %d
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class Test {
}
?>
--EXPECTF--
Fatal error: Hooked virtual properties cannot be readonly in %s on line %d
Fatal error: Hooked virtual properties may not be declared readonly in %s on line %d
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Virtual readonly property in interface throws
Interface properties cannot be readonly
--FILE--
<?php

Expand All @@ -8,4 +8,4 @@ interface Test {
}
?>
--EXPECTF--
Fatal error: Hooked virtual properties cannot be readonly in %s on line %d
Fatal error: Interface properties may not be declared readonly in %s on line %d
11 changes: 10 additions & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -8499,7 +8499,16 @@ static void zend_compile_property_hooks(

/* Allow hooks on backed readonly properties only. */
if ((prop_info->flags & (ZEND_ACC_READONLY|ZEND_ACC_VIRTUAL)) == (ZEND_ACC_READONLY|ZEND_ACC_VIRTUAL)) {
zend_error_noreturn(E_COMPILE_ERROR, "Hooked virtual properties cannot be readonly");

if (ce->ce_flags & ZEND_ACC_INTERFACE) {
zend_error_noreturn(E_COMPILE_ERROR, "Interface properties may not be declared readonly");
}

if (ce->ce_flags & (ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) {
zend_error_noreturn(E_COMPILE_ERROR, "Hooked properties in abstract classes may not be declared readonly");
}

zend_error_noreturn(E_COMPILE_ERROR, "Hooked virtual properties may not be declared readonly");
}

if (hooks->children == 0) {
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy