|
| 1 | +--TEST-- |
| 2 | +PFA with $this placeholder basics |
| 3 | +--FILE-- |
| 4 | +<?php |
| 5 | + |
| 6 | +class C { |
| 7 | + function f($a = null, $b = null) { |
| 8 | + printf("%s::%s(%s, %s)\n", get_class($this), __FUNCTION__, $a, $b); |
| 9 | + } |
| 10 | +} |
| 11 | + |
| 12 | +echo "# Basics\n"; |
| 13 | + |
| 14 | +$f = C::f($this: ?, ?, ?); |
| 15 | +echo new ReflectionFunction($f), "\n"; |
| 16 | +$f(new C, 'a', 'b'); |
| 17 | + |
| 18 | +echo "\n# \$this: can be used anywhere, and makes anything before it required\n"; |
| 19 | + |
| 20 | +$f = C::f(?, $this: ?, ?); |
| 21 | +echo new ReflectionFunction($f), "\n"; |
| 22 | +$f('a', new C, 'b'); |
| 23 | + |
| 24 | +echo "\n# \$this: can be used anywhere, and makes anything before it required (2)\n"; |
| 25 | + |
| 26 | +$f = C::f(?, ?, $this: ?); |
| 27 | +echo new ReflectionFunction($f), "\n"; |
| 28 | +$f('a', 'b', new C); |
| 29 | + |
| 30 | +echo "\n# \$this: can be used anywhere (variadic placeholder)\n"; |
| 31 | + |
| 32 | +$f = C::f($this: ?, ...); |
| 33 | +echo new ReflectionFunction($f), "\n"; |
| 34 | +$f(new C, 'a', 'b'); |
| 35 | + |
| 36 | +echo "\n# \$this: can be used anywhere (names params)\n"; |
| 37 | + |
| 38 | +$f = C::f(b: ?, $this: ?, a: ?); |
| 39 | +echo new ReflectionFunction($f), "\n"; |
| 40 | +$f('b', new C, 'a'); |
| 41 | + |
| 42 | +?> |
| 43 | +--EXPECTF-- |
| 44 | +# Basics |
| 45 | +Closure [ <user> static public method {closure:pfa:%s:11} ] { |
| 46 | + @@ %s 11 - 11 |
| 47 | + |
| 48 | + - Parameters [3] { |
| 49 | + Parameter #0 [ <required> C $__this ] |
| 50 | + Parameter #1 [ <optional> $a = NULL ] |
| 51 | + Parameter #2 [ <optional> $b = NULL ] |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +C::f(a, b) |
| 56 | + |
| 57 | +# $this: can be used anywhere, and makes anything before it required |
| 58 | +Closure [ <user> static public method {closure:pfa:%s:17} ] { |
| 59 | + @@ %s 17 - 17 |
| 60 | + |
| 61 | + - Parameters [3] { |
| 62 | + Parameter #0 [ <required> $a ] |
| 63 | + Parameter #1 [ <required> C $__this ] |
| 64 | + Parameter #2 [ <optional> $b = NULL ] |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +C::f(a, b) |
| 69 | + |
| 70 | +# $this: can be used anywhere, and makes anything before it required (2) |
| 71 | +Closure [ <user> static public method {closure:pfa:%s:23} ] { |
| 72 | + @@ %s 23 - 23 |
| 73 | + |
| 74 | + - Parameters [3] { |
| 75 | + Parameter #0 [ <required> $a ] |
| 76 | + Parameter #1 [ <required> $b ] |
| 77 | + Parameter #2 [ <required> C $__this ] |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +C::f(a, b) |
| 82 | + |
| 83 | +# $this: can be used anywhere (variadic placeholder) |
| 84 | +Closure [ <user> static public method {closure:pfa:%s:29} ] { |
| 85 | + @@ %s 29 - 29 |
| 86 | + |
| 87 | + - Parameters [3] { |
| 88 | + Parameter #0 [ <required> C $__this ] |
| 89 | + Parameter #1 [ <optional> $a = NULL ] |
| 90 | + Parameter #2 [ <optional> $b = NULL ] |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +C::f(a, b) |
| 95 | + |
| 96 | +# $this: can be used anywhere (names params) |
| 97 | +Closure [ <user> static public method {closure:pfa:%s:35} ] { |
| 98 | + @@ %s 35 - 35 |
| 99 | + |
| 100 | + - Parameters [3] { |
| 101 | + Parameter #0 [ <required> $b ] |
| 102 | + Parameter #1 [ <required> C $__this ] |
| 103 | + Parameter #2 [ <optional> $a = NULL ] |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +C::f(a, b) |
0 commit comments