xref: /php-src/tests/classes/__call_006.phpt (revision f8d79582)
1--TEST--
2Ensure exceptions are handled properly when thrown in __call.
3--FILE--
4<?php
5class A {
6    function __call($strMethod, $arrArgs) {
7        var_dump($this);
8        throw new Exception;
9        echo "You should not see this";
10    }
11    function test() {
12        A::unknownCalledWithSRO(1,2,3);
13    }
14}
15
16class B extends A {
17    function test() {
18        B::unknownCalledWithSROFromChild(1,2,3);
19    }
20}
21
22$a = new A();
23
24echo "---> Invoke __call via simple method call.\n";
25try {
26    $a->unknown();
27} catch (Exception $e) {
28    echo "Exception caught OK; continuing.\n";
29}
30
31echo "\n\n---> Invoke __call via scope resolution operator within instance.\n";
32try {
33    $a->test();
34} catch (Exception $e) {
35    echo "Exception caught OK; continuing.\n";
36}
37
38echo "\n\n---> Invoke __call via scope resolution operator within child instance.\n";
39$b = new B();
40try {
41    $b->test();
42} catch (Exception $e) {
43    echo "Exception caught OK; continuing.\n";
44}
45
46echo "\n\n---> Invoke __call via callback.\n";
47try {
48    call_user_func(array($b, 'unknownCallback'), 1,2,3);
49} catch (Exception $e) {
50    echo "Exception caught OK; continuing.\n";
51}
52?>
53--EXPECTF--
54---> Invoke __call via simple method call.
55object(A)#%d (0) {
56}
57Exception caught OK; continuing.
58
59
60---> Invoke __call via scope resolution operator within instance.
61object(A)#%d (0) {
62}
63Exception caught OK; continuing.
64
65
66---> Invoke __call via scope resolution operator within child instance.
67object(B)#%d (0) {
68}
69Exception caught OK; continuing.
70
71
72---> Invoke __call via callback.
73object(B)#%d (0) {
74}
75Exception caught OK; continuing.
76