xref: /PHP-5.6/ext/reflection/tests/bug38465.phpt (revision 30a8d14f)
1--TEST--
2Bug #38465 (ReflectionParameter fails on access to self::)
3--FILE--
4<?php
5class Baz {
6    const B = 3;
7}
8
9class Foo {
10    const X = 1;
11    public function x($a = self::X, $b = Baz::B, $c = 99) {}
12}
13
14class Bar extends Foo {
15    const Y = 2;
16    public function y($a = self::Y, $b = Baz::B, $c = 99) {}
17}
18
19
20echo "From global scope:\n";
21
22$clazz = new ReflectionClass('Bar');
23foreach ($clazz->getMethods() as $method) {
24    foreach ($method->getParameters() as $param) {
25        if ($param->isDefaultValueAvailable()) {
26            echo $method->getDeclaringClass()->getName(), '::', $method->getName(), '($', $param->getName(), ' = ', $param->getDefaultValue(), ")\n";
27        }
28    }
29}
30
31echo "\nFrom class context:\n";
32
33class Test {
34    function __construct() {
35        $clazz = new ReflectionClass('Bar');
36        foreach ($clazz->getMethods() as $method) {
37            foreach ($method->getParameters() as $param) {
38                if ($param->isDefaultValueAvailable()) {
39                    echo $method->getDeclaringClass()->getName(), '::', $method->getName(), '($', $param->getName(), ' = ', $param->getDefaultValue(), ")\n";
40                }
41            }
42        }
43    }
44}
45
46new Test();
47
48?>
49--EXPECT--
50From global scope:
51Bar::y($a = 2)
52Bar::y($b = 3)
53Bar::y($c = 99)
54Foo::x($a = 1)
55Foo::x($b = 3)
56Foo::x($c = 99)
57
58From class context:
59Bar::y($a = 2)
60Bar::y($b = 3)
61Bar::y($c = 99)
62Foo::x($a = 1)
63Foo::x($b = 3)
64Foo::x($c = 99)
65