mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
RFC: https://wiki.php.net/rfc/property-hooks Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
52 lines
844 B
PHP
52 lines
844 B
PHP
--TEST--
|
|
Different kinds of indirect modification with by-val and by-ref getters
|
|
--FILE--
|
|
<?php
|
|
|
|
|
|
class Test {
|
|
public $byVal {
|
|
set {
|
|
echo __METHOD__, "\n";
|
|
$this->byVal = $value;
|
|
}
|
|
}
|
|
}
|
|
|
|
$test = new Test;
|
|
|
|
$test->byVal = 0;
|
|
$test->byVal++;
|
|
++$test->byVal;
|
|
$test->byVal += 1;
|
|
var_dump($test->byVal);
|
|
$test->byVal = [];
|
|
try {
|
|
$test->byVal[] = 1;
|
|
} catch (\Error $e) {
|
|
echo $e->getMessage(), "\n";
|
|
}
|
|
var_dump($test->byVal);
|
|
try {
|
|
$ref =& $test->byVal;
|
|
} catch (\Error $e) {
|
|
echo $e->getMessage(), "\n";
|
|
}
|
|
$ref = 42;
|
|
var_dump($test->byVal);
|
|
|
|
?>
|
|
--EXPECT--
|
|
Test::$byVal::set
|
|
Test::$byVal::set
|
|
Test::$byVal::set
|
|
Test::$byVal::set
|
|
int(3)
|
|
Test::$byVal::set
|
|
Indirect modification of Test::$byVal is not allowed
|
|
array(0) {
|
|
}
|
|
Indirect modification of Test::$byVal is not allowed
|
|
array(0) {
|
|
}
|