mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
First pass at moving `Zend/tests/gh*` tests to existing sub directories Work towards GH-15631
43 lines
712 B
PHP
43 lines
712 B
PHP
--TEST--
|
|
GH-10377 (Unable to have an anonymous readonly class)
|
|
--FILE--
|
|
<?php
|
|
|
|
$readonly_anon = new readonly class {
|
|
public int $field;
|
|
function __construct() {
|
|
$this->field = 2;
|
|
}
|
|
};
|
|
|
|
$anon = new class {
|
|
public int $field;
|
|
function __construct() {
|
|
$this->field = 2;
|
|
}
|
|
};
|
|
|
|
var_dump($readonly_anon->field);
|
|
try {
|
|
$readonly_anon->field = 123;
|
|
} catch (Error $e) {
|
|
echo $e->getMessage() . "\n";
|
|
}
|
|
var_dump($readonly_anon->field);
|
|
|
|
var_dump($anon->field);
|
|
try {
|
|
$anon->field = 123;
|
|
} catch (Error $e) {
|
|
echo $e->getMessage() . "\n";
|
|
}
|
|
var_dump($anon->field);
|
|
|
|
?>
|
|
--EXPECT--
|
|
int(2)
|
|
Cannot modify readonly property class@anonymous::$field
|
|
int(2)
|
|
int(2)
|
|
int(123)
|