cache_slot.phpt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. --TEST--
  2. Test interaction with cache slots
  3. --FILE--
  4. <?php
  5. class Test {
  6. public readonly string $prop;
  7. public readonly array $prop2;
  8. public readonly object $prop3;
  9. public function setProp(string $prop) {
  10. $this->prop = $prop;
  11. }
  12. public function initAndAppendProp2() {
  13. $this->prop2 = [];
  14. $this->prop2[] = 1;
  15. }
  16. public function initProp3() {
  17. $this->prop3 = new stdClass;
  18. $this->prop3->foo = 1;
  19. }
  20. public function replaceProp3() {
  21. $ref =& $this->prop3;
  22. $ref = new stdClass;
  23. }
  24. }
  25. $test = new Test;
  26. $test->setProp("a");
  27. var_dump($test->prop);
  28. try {
  29. $test->setProp("b");
  30. } catch (Error $e) {
  31. echo $e->getMessage(), "\n";
  32. }
  33. var_dump($test->prop);
  34. echo "\n";
  35. $test = new Test;
  36. try {
  37. $test->initAndAppendProp2();
  38. } catch (Error $e) {
  39. echo $e->getMessage(), "\n";
  40. }
  41. try {
  42. $test->initAndAppendProp2();
  43. } catch (Error $e) {
  44. echo $e->getMessage(), "\n";
  45. }
  46. var_dump($test->prop2);
  47. echo "\n";
  48. $test = new Test;
  49. $test->initProp3();
  50. $test->replaceProp3();
  51. var_dump($test->prop3);
  52. $test->replaceProp3();
  53. var_dump($test->prop3);
  54. echo "\n";
  55. // Test variations using closure rebinding, so we have unknown property_info in JIT.
  56. $test = new Test;
  57. (function() { $this->prop2 = []; })->call($test);
  58. $appendProp2 = (function() {
  59. $this->prop2[] = 1;
  60. })->bindTo($test, Test::class);
  61. try {
  62. $appendProp2();
  63. } catch (Error $e) {
  64. echo $e->getMessage(), "\n";
  65. }
  66. try {
  67. $appendProp2();
  68. } catch (Error $e) {
  69. echo $e->getMessage(), "\n";
  70. }
  71. var_dump($test->prop2);
  72. echo "\n";
  73. $test = new Test;
  74. $replaceProp3 = (function() {
  75. $ref =& $this->prop3;
  76. $ref = new stdClass;
  77. })->bindTo($test, Test::class);
  78. $test->initProp3();
  79. $replaceProp3();
  80. var_dump($test->prop3);
  81. $replaceProp3();
  82. var_dump($test->prop3);
  83. ?>
  84. --EXPECT--
  85. string(1) "a"
  86. Cannot modify readonly property Test::$prop
  87. string(1) "a"
  88. Cannot modify readonly property Test::$prop2
  89. Cannot modify readonly property Test::$prop2
  90. array(0) {
  91. }
  92. object(stdClass)#3 (1) {
  93. ["foo"]=>
  94. int(1)
  95. }
  96. object(stdClass)#3 (1) {
  97. ["foo"]=>
  98. int(1)
  99. }
  100. Cannot modify readonly property Test::$prop2
  101. Cannot modify readonly property Test::$prop2
  102. array(0) {
  103. }
  104. object(stdClass)#5 (1) {
  105. ["foo"]=>
  106. int(1)
  107. }
  108. object(stdClass)#5 (1) {
  109. ["foo"]=>
  110. int(1)
  111. }