summaryrefslogtreecommitdiff
path: root/ext/reflection/tests/ReflectionClass_getInterfaces_003.phpt
blob: 74044f7531d3a39154e09e7c47b5c28bf3702cd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
--TEST--
ReflectionClass::getInterfaces() - odd ampersand behaviour.
--CREDITS--
Robin Fernandes <robinf@php.net>
Steve Seear <stevseea@php.net>
--FILE--
<?php

echo "An object is in an array and is referenced. As expected, var_dumping the array shows '&':\n";
$a = array(new stdclass);
$b =& $a[0];
var_dump($a);

echo "Naturally, this remains true if we modify the object:\n";
$a[0]->x = 1;
var_dump($a);


echo "\n\nObtain the array of interfaces implemented by C.\n";
interface I {}
class C implements I {}
$rc = new ReflectionClass('C');
$a = $rc->getInterfaces();
echo "The result is an array in which each element is an object (an instance of ReflectionClass)\n";
echo "Var_dumping this array shows that the elements are referenced. By what?\n";
var_dump($a);

echo "Modify the object, and it is apparently no longer referenced.\n";
$a['I']->x = 1;
var_dump($a);

?>
--EXPECTF--
An object is in an array and is referenced. As expected, var_dumping the array shows '&':
array(1) {
  [0]=>
  &object(stdClass)#%d (0) {
  }
}
Naturally, this remains true if we modify the object:
array(1) {
  [0]=>
  &object(stdClass)#%d (1) {
    ["x"]=>
    int(1)
  }
}


Obtain the array of interfaces implemented by C.
The result is an array in which each element is an object (an instance of ReflectionClass)
Var_dumping this array shows that the elements are referenced. By what?
array(1) {
  ["I"]=>
  &object(ReflectionClass)#%d (1) {
    ["name"]=>
    string(1) "I"
  }
}
Modify the object, and it is apparently no longer referenced.
array(1) {
  ["I"]=>
  object(ReflectionClass)#%d (2) {
    ["name"]=>
    string(1) "I"
    ["x"]=>
    int(1)
  }
}