xref: /PHP-7.1/tests/lang/038.phpt (revision 610c7fbe)
1--TEST--
2Convert warnings to exceptions
3--FILE--
4<?php
5
6class MyException extends Exception
7{
8	function __construct($errstr, $errno=0, $errfile='', $errline='')
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===DONE===
37<?php exit(0); ?>
38--EXPECTF--
39string(15) "Error2Exception"
40string(5) "fopen"
41===DONE===
42