1--TEST-- 2Interaction with magic get/set 3--FILE-- 4<?php 5 6class Test { 7 public readonly int $prop; 8 9 public function unsetProp() { 10 unset($this->prop); 11 } 12 13 public function __get($name) { 14 echo __METHOD__, "($name)\n"; 15 return 1; 16 } 17 18 public function __set($name, $value) { 19 echo __METHOD__, "($name, $value)\n"; 20 } 21 22 public function __unset($name) { 23 echo __METHOD__, "($name)\n"; 24 } 25 26 public function __isset($name) { 27 echo __METHOD__, "($name)\n"; 28 return true; 29 } 30} 31 32$test = new Test; 33 34// The property is in uninitialized state, no magic methods should be invoked. 35var_dump(isset($test->prop)); 36try { 37 var_dump($test->prop); 38} catch (Error $e) { 39 echo $e->getMessage(), "\n"; 40} 41try { 42 $test->prop = 1; 43} catch (Error $e) { 44 echo $e->getMessage(), "\n"; 45} 46try { 47 unset($test->prop); 48} catch (Error $e) { 49 echo $e->getMessage(), "\n"; 50} 51 52$test->unsetProp(); 53 54var_dump(isset($test->prop)); 55var_dump($test->prop); 56$test->prop = 2; 57try { 58 unset($test->prop); 59} catch (Error $e) { 60 echo $e->getMessage(), "\n"; 61} 62 63?> 64--EXPECT-- 65bool(false) 66Typed property Test::$prop must not be accessed before initialization 67Cannot initialize readonly property Test::$prop from global scope 68Cannot unset readonly property Test::$prop from global scope 69Test::__isset(prop) 70bool(true) 71Test::__get(prop) 72int(1) 73Test::__set(prop, 2) 74Test::__unset(prop) 75