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: adjusted test error message formatting
  • Loading branch information
NickSdot committed Jun 14, 2025
commit b4df02dec728e626b486b0d34438d9b6cd902c8a
8 changes: 4 additions & 4 deletions Zend/tests/property_hooks/readonly_class_property_backed.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ var_dump($t->prop);
try {
$t->set(43);
} catch (Error $e) {
echo $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
$t->prop = 43;
} catch (Error $e) {
echo $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
var_dump($t->prop);
?>
--EXPECT--
int(42)
Cannot modify readonly property Test::$prop
Cannot modify protected(set) readonly property Test::$prop from global scope
Error: Cannot modify readonly property Test::$prop
Error: Cannot modify protected(set) readonly property Test::$prop from global scope
int(42)
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ var_dump($t->prop);
try {
$t->set(43);
} catch (Error $e) {
echo $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
$t->prop = 43;
} catch (Error $e) {
echo $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
var_dump($t->prop);
?>
--EXPECT--
int(42)
Cannot modify readonly property Test::$prop
Cannot modify protected(set) readonly property Test::$prop from global scope
Error: Cannot modify readonly property Test::$prop
Error: Cannot modify protected(set) readonly property Test::$prop from global scope
int(42)
8 changes: 4 additions & 4 deletions Zend/tests/property_hooks/readonly_property_backed.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ var_dump($t->prop);
try {
$t->set(43);
} catch (Error $e) {
echo $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
$t->prop = 43;
} catch (Error $e) {
echo $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
var_dump($t->prop);

Expand Down Expand Up @@ -79,8 +79,8 @@ final readonly class Foo3
?>
--EXPECT--
int(42)
Cannot modify readonly property Test::$prop
Cannot modify protected(set) readonly property Test::$prop from global scope
Error: Cannot modify readonly property Test::$prop
Error: Cannot modify protected(set) readonly property Test::$prop from global scope
int(42)
array(3) {
[0]=>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ $t->getParentValue();
try {
$t->setAgain(); // cannot write, readonly
} catch (Error $e) {
echo $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
$t->prop = 43; // cannot write, visibility
} catch (Error $e) {
echo $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

?>
Expand Down Expand Up @@ -93,5 +93,5 @@ In ChildClass::$prop::get():
parent::$prop::get(): 911
$this->prop: 911
$this->prop * 2: 1822
Cannot modify readonly property ChildClass::$prop
Cannot modify protected(set) readonly property ChildClass::$prop from global scope
Error: Cannot modify readonly property ChildClass::$prop
Error: Cannot modify protected(set) readonly property ChildClass::$prop from global scope
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ var_dump($t->prop);
try {
$t->set(43);
} catch (Error $e) {
echo $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
$t->prop = 43;
} catch (Error $e) {
echo $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
var_dump($t->prop);
?>
--EXPECT--
int(42)
Cannot modify readonly property Test::$prop
Cannot modify protected(set) readonly property Test::$prop from global scope
Error: Cannot modify readonly property Test::$prop
Error: Cannot modify protected(set) readonly property Test::$prop from global scope
int(42)
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var_dump($product);
try {
$categoryId->setValue($product, '420');
} catch (Error $e) {
echo $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

?>
Expand All @@ -102,4 +102,4 @@ object(LazyProduct)#2 (5) {
["categoryId":"LazyProduct":private]=>
string(2) "42"
}
Cannot modify readonly property LazyProduct::$categoryId
Error: Cannot modify readonly property LazyProduct::$categoryId
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var_dump($one);
try {
$two = new PositivePoint(0,1);
} catch (Error $e) {
echo $e->getMessage(), "\n";
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}


Expand All @@ -29,4 +29,4 @@ object(PositivePoint)#1 (2) {
["y"]=>
int(1)
}
Value must be greater 0
Error: Value must be greater 0
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