1--TEST--
2Pdo\Pgsql::setNoticeCallback catches Postgres "raise notice".
3--SKIPIF--
4<?php
5if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded');
6require_once dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
7require_once dirname(__FILE__) . '/config.inc';
8PDOTest::skip();
9?>
10--FILE--
11<?php
12class Logger
13{
14    public function disp($message) { echo trim($message)."\n"; }
15    public function dispRe($message) { echo "Re".trim($message)."\n"; }
16    public function __call(string $method, array $args)
17    {
18        $realMethod = strtr($method, [ 'whatever' => 'disp' ]);
19        if (!method_exists($this, $realMethod)) {
20            throw new BadMethodCallException('Call to undefined method '.__CLASS__.'::'.$realMethod);
21        }
22        echo "$method trampoline for $realMethod\n";
23        return call_user_func_array([ $this, $realMethod ], $args);
24    }
25}
26$logger = new Logger();
27function attach($db, $method)
28{
29    global $logger;
30    $db->setNoticeCallback([ $logger, $method ]);
31}
32echo "Testing with method explicitely plugged:\n";
33$rounds = [ 'disp', 'dispRe' ];
34require dirname(__FILE__) . '/issue78621.inc';
35echo "Testing with a bit of magic:\n";
36$rounds = [ 'whatever', 'whateverRe', 'unexisting' ];
37require dirname(__FILE__) . '/issue78621.inc';
38?>
39--EXPECT--
40Testing with method explicitely plugged:
41NOTICE:  I tampered your data, did you know?
42ReNOTICE:  I tampered your data, did you know?
43array(1) {
44  [0]=>
45  array(1) {
46    ["a"]=>
47    string(2) "oh"
48  }
49}
50Done
51Testing with a bit of magic:
52whatever trampoline for disp
53NOTICE:  I tampered your data, did you know?
54whateverRe trampoline for dispRe
55ReNOTICE:  I tampered your data, did you know?
56Caught BadMethodCallException Call to undefined method Logger::unexisting
57array(1) {
58  [0]=>
59  array(1) {
60    ["a"]=>
61    string(2) "oh"
62  }
63}
64Done
65