summaryrefslogtreecommitdiff
path: root/ext/spl/tests/class_uses_basic2.phpt
blob: a0ffe8b861f669ace8bd92575ed3185d3c88d097 (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--
SPL: Test class_uses() function : basic 
--FILE--
<?php
/* Prototype  : array class_uses(mixed what [, bool autoload ])
 * Description: Return all traits used by a class
 * Source code: ext/spl/php_spl.c
 * Alias to functions: 
 */

echo "*** Testing class_uses() : basic ***\n";


trait foo { }
class fooUser { use foo; }

trait bar { }
class barUser { use bar; }

class foobarUser { use foo, bar; }

/** There is no semantics for traits in the inheritance chain.
    Traits are flattend into a class, and that semantics is nothing
    like a type, or interface, and thus, not propergated. */
class fooViaBarUser extends barUser { use foo; }

class fooExtended extends fooUser {}

s_var_dump(class_uses(new foobarUser));
s_var_dump(class_uses('foobarUser'));
s_var_dump(class_uses(new fooViaBarUser));
s_var_dump(class_uses('fooViaBarUser'));
s_var_dump(class_uses(new fooExtended));
s_var_dump(class_uses('fooExtended'));


function s_var_dump($arr) {
   krsort($arr);
   var_dump($arr);
}
?>
===DONE===
--EXPECT--
*** Testing class_uses() : basic ***
array(2) {
  ["foo"]=>
  string(3) "foo"
  ["bar"]=>
  string(3) "bar"
}
array(2) {
  ["foo"]=>
  string(3) "foo"
  ["bar"]=>
  string(3) "bar"
}
array(1) {
  ["foo"]=>
  string(3) "foo"
}
array(1) {
  ["foo"]=>
  string(3) "foo"
}
array(0) {
}
array(0) {
}
===DONE===