xref: /PHP-8.1/tests/lang/038.phpt (revision 30a082cb)
1--TEST--
2Convert warnings to exceptions
3--FILE--
4<?php
5
6class MyException extends Exception
7{
8    function __construct($errstr, $errno=0, $errfile='', $errline=0)
9    {
10        parent::__construct($errstr, $errno);
11        $this->file = $errfile;
12        $this->line = $errline;
13    }
14}
15
16function Error2Exception($errno, $errstr, $errfile, $errline)
17{
18    throw new MyException($errstr, $errno);//, $errfile, $errline);
19}
20
21$err_msg = 'no exception';
22set_error_handler('Error2Exception');
23
24try
25{
26    $con = fopen("/tmp/a_file_that_does_not_exist",'r');
27}
28catch (Exception $e)
29{
30    $trace = $e->getTrace();
31    var_dump($trace[0]['function']);
32    var_dump($trace[1]['function']);
33}
34
35?>
36--EXPECT--
37string(15) "Error2Exception"
38string(5) "fopen"
39