xref: /PHP-7.0/Zend/tests/bug33512.phpt (revision 4b953534)
1--TEST--
2Bug #33512 (unset() overloaded properties doesn't work)
3--FILE--
4<?php
5class TheObj {
6		public $RealVar1, $RealVar2, $RealVar3, $RealVar4;
7		public $Var = array();
8
9		function __set($var, $val) {
10			$this->Var[$var] = $val;
11		}
12		function __get($var) {
13			if(isset($this->Var[$var])) return $this->Var[$var];
14			else return -1;
15		}
16		function __unset($var) {
17			unset($this->Var[$var]);
18		}
19	}
20
21	$SomeObj = new TheObj;
22
23	// this will fine
24	$SomeObj->RealVar1 = 'somevalue';
25	$SomeObj->{'RealVar2'} = 'othervalue';
26	$SomeObj->{'RealVar'.(3)} = 'othervaluetoo';
27	$SomeObj->{'RealVar'.'4'} = 'anothervalue';
28
29	// this will fine too
30	$SomeObj->Virtual1 = 'somevalue';
31	$SomeObj->{'Virtual2'} = 'othervalue';
32
33	// it's can't be used since this will encounter error
34	$SomeObj->{'Virtual'.(3)} = 'othervaluetoo';
35	$SomeObj->{'Virtual'.'4'} = 'anothervalue';
36
37	// but this will fine, ofcourse
38	$SomeObj->Var['Virtual'.(3)] = 'othervaluetoo';
39	$SomeObj->Var['Virtual'.'4'] = 'anothervalue';
40
41
42	var_dump($SomeObj->RealVar1);
43	print $SomeObj->{'RealVar'.(3)}."\n";
44
45	unset($SomeObj->RealVar1);
46	unset($SomeObj->{'RealVar'.(3)});
47
48	//the lines below will catch by '__get' magic method since these variables are unavailable anymore
49	var_dump($SomeObj->RealVar1);
50	print $SomeObj->{'RealVar'.(3)}."\n";
51
52	// now we will try to unset these variables
53	unset($SomeObj->Virtual1);
54	unset($SomeObj->{'Virtual'.(3)});
55
56	//but, these variables are still available??? even though they're "unset"-ed
57	print $SomeObj->Virtual1."\n";
58	print $SomeObj->{'Virtual'.(3)}."\n";
59?>
60--EXPECT--
61string(9) "somevalue"
62othervaluetoo
63int(-1)
64-1
65-1
66-1
67