Doc #76636 [Sus]: autoloading catches and rethrows exceptions
Edit report at https://bugs.php.net/bug.php?id=76636&edit=1
ID: 76636
Updated by: requinix@php.net
Reported by: sugerliedear at gmail dot com
Summary: autoloading catches and rethrows exceptions
Status: Suspended
Type: Documentation Problem
Package: Scripting Engine problem
Operating System: centos65
PHP Version: 7.2.7
Assigned To: requinix
Block user comment: N
Private report: N
New Comment:
Oh, and I forgot:
Do not blindly require() files in an autoloader. Check that they exist first with is_file().
Previous Comments:
------------------------------------------------------------------------
[2018-07-17 11:45:27] requinix@php.net
Your first autoloader will throw an exception, but PHP catches it and continues autoloading. When
autoloading completes the exception would have been rethrown, however your second autoloader fails
with a fatal *error* so PHP exits before that happens.
...but that only applies to PHP 7.2 and earlier. See bug #74372.
spl_autoload_register should get a changelog entry about 7.3 so I'm suspending this until
that's released.
------------------------------------------------------------------------
[2018-07-17 10:16:26] sugerliedear at gmail dot com
Description:
------------
When i invoke spl_autoload_register two times, E_PARSE error not throw in the spl_autoload_register
in the first time.
Test script:
---------------
https://github.com/khadgarmage/hello-world/blob/master/php72-bug1.md
Expected result:
----------------
root@/mnt/htdocs $ php72 t.php
object(ParseError)#3 (7) {
["message":protected]=>
string(95) "syntax error, unexpected 'fdsaf' (T_STRING), expecting function
(T_FUNCTION) or const (T_CONST)"
["string":"Error":private]=>
string(0) ""
["code":protected]=>
int(0)
["file":protected]=>
string(17) "/data2/mytest.php"
["line":protected]=>
int(3)
["trace":"Error":private]=>
array(2) {
[0]=>
array(2) {
["function"]=>
string(9) "{closure}"
["args"]=>
array(1) {
[0]=>
string(6) "mytest"
}
}
[1]=>
array(4) {
["file"]=>
string(12) "/data2/t.php"
["line"]=>
int(23)
["function"]=>
string(17) "spl_autoload_call"
["args"]=>
array(1) {
[0]=>
string(6) "mytest"
}
}
}
["previous":"Error":private]=>
NULL
}
PHP Warning: require_once(namespace\mytest.php): failed to open stream: No such file or directory
in /data2/t.php on line 19
PHP Fatal error: require_once(): Failed opening required 'namespace\mytest.php'
(include_path='.:/opt/remi/php72/root/usr/share/pear:/opt/remi/php72/root/usr/share/php:/usr/share/pear:/usr/share/php')
in /data2/t.php on line 19
Actual result:
--------------
root@/mnt/htdocs $ php72 t.php
PHP Warning: require_once(namespace\mytest.php): failed to open stream: No such file or directory
in /data2/t.php on line 15
PHP Fatal error: require_once(): Failed opening required 'namespace\mytest.php'
(include_path='.:/opt/remi/php72/root/usr/share/pear:/opt/remi/php72/root/usr/share/php:/usr/share/pear:/usr/share/php')
in /data2/t.php on line 15
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76636&edit=1
Thread (3 messages)