1--TEST-- 2Asymmetric visibility variations 3--FILE-- 4<?php 5 6class Test { 7 public private(set) int $prop; 8 public private(set) array $array; 9 10 public function init() { 11 $this->prop = 1; 12 $this->array = []; 13 } 14 15 public function r() { 16 echo $this->prop; 17 } 18 19 public function w() { 20 $this->prop = 1; 21 echo 'done'; 22 } 23 24 public function rw() { 25 $this->prop += 1; 26 echo 'done'; 27 } 28 29 public function im() { 30 $this->array[] = 1; 31 echo 'done'; 32 } 33 34 public function is() { 35 echo (int) isset($this->prop); 36 } 37 38 public function us() { 39 unset($this->prop); 40 echo 'done'; 41 } 42 43 public function us_dim() { 44 unset($this->array[0]); 45 echo 'done'; 46 } 47} 48 49function r($test) { 50 echo $test->prop; 51} 52 53function w($test) { 54 $test->prop = 0; 55 echo 'done'; 56} 57 58function rw($test) { 59 $test->prop += 1; 60 echo 'done'; 61} 62 63function im($test) { 64 $test->array[] = 1; 65 echo 'done'; 66} 67 68function is($test) { 69 echo (int) isset($test->prop); 70} 71 72function us($test) { 73 unset($test->prop); 74 echo 'done'; 75} 76 77function us_dim($test) { 78 unset($test->array[0]); 79 echo 'done'; 80} 81 82foreach ([true, false] as $init) { 83 foreach ([true, false] as $scope) { 84 foreach (['r', 'w', 'rw', 'im', 'is', 'us', 'us_dim'] as $op) { 85 $test = new Test(); 86 if ($init) { 87 $test->init(); 88 } 89 90 echo 'Init: ' . ((int) $init) . ', scope: ' . ((int) $scope) . ', op: ' . $op . ": "; 91 try { 92 if ($scope) { 93 $test->{$op}(); 94 } else { 95 $op($test); 96 } 97 } catch (Error $e) { 98 echo $e->getMessage(); 99 } 100 echo "\n"; 101 } 102 } 103} 104 105?> 106--EXPECT-- 107Init: 1, scope: 1, op: r: 1 108Init: 1, scope: 1, op: w: done 109Init: 1, scope: 1, op: rw: done 110Init: 1, scope: 1, op: im: done 111Init: 1, scope: 1, op: is: 1 112Init: 1, scope: 1, op: us: done 113Init: 1, scope: 1, op: us_dim: done 114Init: 1, scope: 0, op: r: 1 115Init: 1, scope: 0, op: w: Cannot modify private(set) property Test::$prop from global scope 116Init: 1, scope: 0, op: rw: Cannot modify private(set) property Test::$prop from global scope 117Init: 1, scope: 0, op: im: Cannot indirectly modify private(set) property Test::$array from global scope 118Init: 1, scope: 0, op: is: 1 119Init: 1, scope: 0, op: us: Cannot unset private(set) property Test::$prop from global scope 120Init: 1, scope: 0, op: us_dim: Cannot indirectly modify private(set) property Test::$array from global scope 121Init: 0, scope: 1, op: r: Typed property Test::$prop must not be accessed before initialization 122Init: 0, scope: 1, op: w: done 123Init: 0, scope: 1, op: rw: Typed property Test::$prop must not be accessed before initialization 124Init: 0, scope: 1, op: im: done 125Init: 0, scope: 1, op: is: 0 126Init: 0, scope: 1, op: us: done 127Init: 0, scope: 1, op: us_dim: done 128Init: 0, scope: 0, op: r: Typed property Test::$prop must not be accessed before initialization 129Init: 0, scope: 0, op: w: Cannot modify private(set) property Test::$prop from global scope 130Init: 0, scope: 0, op: rw: Typed property Test::$prop must not be accessed before initialization 131Init: 0, scope: 0, op: im: Cannot indirectly modify private(set) property Test::$array from global scope 132Init: 0, scope: 0, op: is: 0 133Init: 0, scope: 0, op: us: Cannot unset private(set) property Test::$prop from global scope 134Init: 0, scope: 0, op: us_dim: done 135