Skip to content

Commit 1c94ff0

Browse files
dstogovnikic
authored andcommitted
Implement engine exceptions
RFC: https://wiki.php.net/rfc/engine_exceptions_for_php7 Pending changes regarding naming of BaseException and whether it should be an interface.
1 parent 2f156c6 commit 1c94ff0

File tree

69 files changed

+2953
-2188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2953
-2188
lines changed

Zend/tests/030.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ $test->bar();
3434
object(Exception)#%d (7) {
3535
["message":protected]=>
3636
string(3) "foo"
37-
["string":"Exception":private]=>
37+
["string":"BaseException":private]=>
3838
string(0) ""
3939
["code":protected]=>
4040
int(0)
4141
["file":protected]=>
4242
string(%d) "%s030.php"
4343
["line":protected]=>
4444
int(%d)
45-
["trace":"Exception":private]=>
45+
["trace":"BaseException":private]=>
4646
array(1) {
4747
[0]=>
4848
array(6) {
@@ -61,7 +61,7 @@ object(Exception)#%d (7) {
6161
}
6262
}
6363
}
64-
["previous":"Exception":private]=>
64+
["previous":"BaseException":private]=>
6565
NULL
6666
}
6767
'test' => '0'

Zend/tests/arg_unpack/string_keys.phpt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ set_error_handler(function($errno, $errstr) {
77
var_dump($errstr);
88
});
99

10-
var_dump(...[1, 2, "foo" => 3, 4]);
11-
var_dump(...new ArrayIterator([1, 2, "foo" => 3, 4]));
10+
try {
11+
var_dump(...[1, 2, "foo" => 3, 4]);
12+
} catch (EngineException $ex) {
13+
var_dump($ex->getMessage());
14+
}
15+
try {
16+
var_dump(...new ArrayIterator([1, 2, "foo" => 3, 4]));
17+
} catch (EngineException $ex) {
18+
var_dump($ex->getMessage());
19+
}
1220

1321
?>
1422
--EXPECTF--
1523
string(36) "Cannot unpack array with string keys"
16-
int(1)
17-
int(2)
1824
string(42) "Cannot unpack Traversable with string keys"
19-
int(1)
20-
int(2)

Zend/tests/bug37251.phpt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22
Bug #37251 (deadlock when custom error handler is to catch array type hint error)
33
--FILE--
44
<?php
5-
function error_handler($errno, $errstr, $errfile, $errline, $context) {
6-
echo 'OK';
7-
}
8-
9-
set_error_handler('error_handler');
10-
115
class Foo {
126
function bar(array $foo) {
137
}
148
}
159

16-
$foo = new Foo();
17-
$foo->bar();
10+
try {
11+
$foo = new Foo();
12+
$foo->bar();
13+
} catch (EngineException $e) {
14+
echo 'OK';
15+
}
1816
--EXPECT--
1917
OK

Zend/tests/bug48693.phpt

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,43 @@ Bug #48693 (Double declaration of __lambda_func when lambda wrongly formatted)
33
--FILE--
44
<?php
55

6-
$x = create_function('', 'return 1; }');
7-
$y = create_function('', 'function a() { }; return 2;');
8-
$z = create_function('', '{');
9-
$w = create_function('', 'return 3;');
6+
try {
7+
$x = create_function('', 'return 1; }');
8+
} catch (ParseException $e) {
9+
echo "$e\n\n";
10+
}
11+
try {
12+
$y = create_function('', 'function a() { }; return 2;');
13+
} catch (ParseException $e) {
14+
echo "$e\n\n";
15+
}
16+
try {
17+
$z = create_function('', '{');
18+
} catch (ParseException $e) {
19+
echo "$e\n\n";
20+
}
21+
try {
22+
$w = create_function('', 'return 3;');
23+
} catch (ParseException $e) {
24+
echo "$e\n\n";
25+
}
1026

1127
var_dump(
12-
$x,
1328
$y(),
14-
$z,
15-
$w(),
16-
$y != $z
29+
$w()
1730
);
1831

1932
?>
2033
--EXPECTF--
21-
Parse error: %s in %s(%d) : runtime-created function on line 1
34+
exception 'ParseException' with message 'syntax error, unexpected '}', expecting end of file' in %sbug48693.php(4) : runtime-created function:1
35+
Stack trace:
36+
#0 %sbug48693.php(4): create_function('', 'return 1; }')
37+
#1 {main}
38+
39+
exception 'ParseException' with message 'syntax error, unexpected end of file' in %sbug48693.php(14) : runtime-created function:1
40+
Stack trace:
41+
#0 %sbug48693.php(14): create_function('', '{')
42+
#1 {main}
2243

23-
Parse error: %s %s(%d) : runtime-created function on line 1
24-
bool(false)
2544
int(2)
26-
bool(false)
2745
int(3)
28-
bool(true)

Zend/tests/bug64135.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function exception_error_handler() {
1010
set_error_handler("exception_error_handler");
1111
try {
1212
$undefined->undefined();
13-
} catch(Exception $e) {
13+
} catch(BaseException $e) {
1414
echo "Exception is thrown";
1515
}
1616
--EXPECT--

Zend/tests/bug64966.phpt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
Bug #64966 (segfault in zend_do_fcall_common_helper_SPEC)
33
--FILE--
44
<?php
5-
error_reporting(E_ALL);
6-
set_error_handler(function($error) { throw new Exception(); }, E_RECOVERABLE_ERROR);
7-
85
function test($func) {
9-
$a = $func("");
6+
try {
7+
$a = $func("");
8+
} catch (EngineException $e) {
9+
throw new Exception();
10+
}
1011
return true;
1112
}
1213
class A {
@@ -20,11 +21,9 @@ $a = new A();
2021
$a->b();
2122
?>
2223
--EXPECTF--
23-
Fatal error: Uncaught exception 'Exception' in %sbug64966.php:3
24+
Fatal error: Uncaught exception 'Exception' in %sbug64966.php:6
2425
Stack trace:
25-
#0 [internal function]: {closure}(4096, 'Argument 1 pass...', '%s', 6, Array)
26-
#1 %sbug64966.php(6): iterator_apply('')
27-
#2 %sbug64966.php(12): test('iterator_apply')
28-
#3 %sbug64966.php(17): A->b()
29-
#4 {main}
30-
thrown in %sbug64966.php on line 3
26+
#0 %sbug64966.php(13): test('iterator_apply')
27+
#1 %sbug64966.php(18): A->b()
28+
#2 {main}
29+
thrown in %sbug64966.php on line 6

Zend/tests/closure_031.phpt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ function foo($errno, $errstr, $errfile, $errline) {
88
set_error_handler('foo');
99
$foo = function() {
1010
};
11-
var_dump($foo->a);
11+
try {
12+
var_dump($foo->a);
13+
} catch (EngineException $ex) {
14+
echo "Error: {$ex->getMessage()}\n";
15+
}
1216
?>
1317
--EXPECT--
1418
Error: Closure object cannot have properties
15-
NULL
1619

Zend/tests/exception_010.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ $x->getcode(1);
1515

1616
?>
1717
--EXPECTF--
18-
Warning: Exception::getTraceAsString() expects exactly 0 parameters, 1 given in %s on line %d
18+
Warning: BaseException::getTraceAsString() expects exactly 0 parameters, 1 given in %s on line %d
1919

20-
Warning: Exception::__toString() expects exactly 0 parameters, 1 given in %s on line %d
20+
Warning: BaseException::__toString() expects exactly 0 parameters, 1 given in %s on line %d
2121

22-
Warning: Exception::getTrace() expects exactly 0 parameters, 1 given in %s on line %d
22+
Warning: BaseException::getTrace() expects exactly 0 parameters, 1 given in %s on line %d
2323

24-
Warning: Exception::getLine() expects exactly 0 parameters, 1 given in %s on line %d
24+
Warning: BaseException::getLine() expects exactly 0 parameters, 1 given in %s on line %d
2525

26-
Warning: Exception::getFile() expects exactly 0 parameters, 1 given in %s on line %d
26+
Warning: BaseException::getFile() expects exactly 0 parameters, 1 given in %s on line %d
2727

28-
Warning: Exception::getMessage() expects exactly 0 parameters, 1 given in %s on line %d
28+
Warning: BaseException::getMessage() expects exactly 0 parameters, 1 given in %s on line %d
2929

30-
Warning: Exception::getCode() expects exactly 0 parameters, 1 given in %s on line %d
30+
Warning: BaseException::getCode() expects exactly 0 parameters, 1 given in %s on line %d

Zend/tests/exception_before_fatal.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,38 @@ set_error_handler("exception_error_handler");
1010

1111
try {
1212
$foo->a();
13-
} catch(Exception $e) {
13+
} catch(BaseException $e) {
1414
var_dump($e->getMessage());
1515
}
1616

1717
try {
1818
new $foo();
19-
} catch(Exception $e) {
19+
} catch(BaseException $e) {
2020
var_dump($e->getMessage());
2121
}
2222

2323
try {
2424
throw $foo;
25-
} catch(Exception $e) {
25+
} catch(BaseException $e) {
2626
var_dump($e->getMessage());
2727
}
2828

2929
try {
3030
$foo();
31-
} catch(Exception $e) {
31+
} catch(BaseException $e) {
3232
var_dump($e->getMessage());
3333
}
3434

3535
try {
3636
$foo::b();
37-
} catch(Exception $e) {
37+
} catch(BaseException $e) {
3838
var_dump($e->getMessage());
3939
}
4040

4141

4242
try {
4343
$b = clone $foo;
44-
} catch(Exception $e) {
44+
} catch(BaseException $e) {
4545
var_dump($e->getMessage());
4646
}
4747

@@ -50,7 +50,7 @@ class b {
5050

5151
try {
5252
b::$foo();
53-
} catch(Exception $e) {
53+
} catch(BaseException $e) {
5454
var_dump($e->getMessage());
5555
}
5656
?>

Zend/tests/generators/bug67497.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ function gen() {
88
yield $a;
99
}
1010

11-
@eval('abc');
11+
try {
12+
eval('abc');
13+
} catch (ParseException $ex) {
14+
}
1215

1316
$values = gen();
1417
$values->next();

0 commit comments

Comments
 (0)