|
| 1 | +--TEST-- |
| 2 | +Anonymous class names are not truncated in runtime error messages |
| 3 | +--FILE-- |
| 4 | +<?php |
| 5 | + |
| 6 | +class A { |
| 7 | + public private(set) int $p = 0; |
| 8 | + private function f() {} |
| 9 | +} |
| 10 | + |
| 11 | +class B { |
| 12 | + private function __destruct() {} |
| 13 | +} |
| 14 | + |
| 15 | +$o = new class { |
| 16 | + public function __construct(public readonly int $ro = 1) {} |
| 17 | + private function priv() {} |
| 18 | + public function ret(): int { return "x"; } |
| 19 | + public function args($a) {} |
| 20 | + public function byRef(&$a) {} |
| 21 | + public function callPriv() { (new A)->f(); } |
| 22 | + public function setPrivateSet() { $a = new A; $a->p = 1; } |
| 23 | + public function destroy() { new B; } |
| 24 | +}; |
| 25 | + |
| 26 | +$v = new class extends ArrayObject { |
| 27 | + public int $virtual { get => 1; } |
| 28 | +}; |
| 29 | + |
| 30 | +foreach ([ |
| 31 | + fn() => $o->priv(), |
| 32 | + fn() => $o->callPriv(), |
| 33 | + fn() => $o->setPrivateSet(), |
| 34 | + fn() => $o->destroy(), |
| 35 | + fn() => $o->ro = 2, |
| 36 | + fn() => $o->ret(), |
| 37 | + fn() => $o->args(), |
| 38 | + fn() => $v->__unserialize([0, [], ['virtual' => 2]]), |
| 39 | +] as $fn) { |
| 40 | + try { |
| 41 | + $fn(); |
| 42 | + } catch (Throwable $e) { |
| 43 | + echo $e::class, ': ', $e->getMessage(), "\n"; |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +$o->byRef(...new ArrayIterator([1])); |
| 48 | + |
| 49 | +?> |
| 50 | +--EXPECTF-- |
| 51 | +Error: Call to private method class@anonymous%0%s::priv() from global scope |
| 52 | +Error: Call to private method A::f() from scope class@anonymous%0%s |
| 53 | +Error: Cannot modify private(set) property A::$p from scope class@anonymous%0%s |
| 54 | +Error: Call to private B::__destruct() from scope class@anonymous%0%s |
| 55 | +Error: Cannot modify readonly property class@anonymous%0%s::$ro |
| 56 | +TypeError: class@anonymous%0%s::ret(): Return value must be of type int, string returned |
| 57 | +ArgumentCountError: Too few arguments to function class@anonymous%0%s::args(), 0 passed in %s on line %d and exactly 1 expected |
| 58 | +Error: Cannot unserialize value for virtual property ArrayObject@anonymous%0%s::$virtual |
| 59 | + |
| 60 | +Warning: Cannot pass by-reference argument 1 of class@anonymous%0%s::byRef() by unpacking a Traversable, passing by-value instead in %s on line %d |
0 commit comments