简体   繁体   English

PHP 7.2-缺少扩展名不会返回错误-停止执行

[英]PHP 7.2 - Missing extensions returns no errors - Stops execution

I fight with that issue already since Wednesday and the result after my research and tests between PHP 5.6 and PHP 7.2 (also 7.1) are: That my PHP 7 doesn't complains or notices missing extensions in my environment. 自从星期三以来,我就一直在与这个问题作斗争,经过我在PHP 5.6PHP 7.2 (也是7.1)之间的研究和测试之后得出的结果是:我的PHP 7不会抱怨或注意到环境中缺少扩展。

Instead of that, it just stops the execuation without an error-message. 取而代之的是,它只是在没有错误消息的情况下停止执行。

Question

Why does PHP 7.x stops executation in the middle of the script* and doesn't fires an Error Notice or Hint for missing PHP-Extensions anymore? 为什么PHP 7.x在脚本中间*停止执行,并且不再为缺少PHP扩展名而发出错误通知或提示?

* Mostly at the position where a function requires to use the specific PHP-Extension. *通常位于函数需要使用特定PHP扩展的位置。

Environment 环境

Operating System :  Debian GNU/Linux 9.6 (stretch)
Web Server       :  nginx/1.10.3
PHP              :  PHP 7.2.12

/etc/apt/sources.list 的/etc/apt/sources.list

# deb cdrom:[Debian GNU/Linux 9.2.1 _Stretch_ - Official amd64 NETINST 20171013-13:07]/ stretch main

#deb cdrom:[Debian GNU/Linux 9.2.1 _Stretch_ - Official amd64 NETINST 20171013-13:07]/ stretch main

deb http://ftp.de.debian.org/debian/ stretch main
deb-src http://ftp.de.debian.org/debian/ stretch main

deb http://security.debian.org/debian-security stretch/updates main
deb-src http://security.debian.org/debian-security stretch/updates main

# stretch-updates, previously known as 'volatile'
deb http://ftp.de.debian.org/debian/ stretch-updates main
deb-src http://ftp.de.debian.org/debian/ stretch-updates main

Issue 问题

While PHP 5.6 complains about missing drivers or invalid function, it just stops execuation when necessary in the middle of my code, without an error message. 虽然PHP 5.6抱怨缺少驱动程序或功能无效,但它只是在必要时在我的代码中间停止执行,而没有错误消息。

Example : If some of these extensions aren't installed, the issue happens: 示例 :如果未安装其中一些扩展,则会发生问题:

php7.2-mysql
php7.2-mbstring
php7.2-soap
php7.2-simplexml

This issue was really confusing, because I had enabled error-reporting and display-errors, startup-errors in my /etc/php/7.2/fpm/php.ini and also work with... 这个问题确实令人困惑,因为我在/etc/php/7.2/fpm/php.ini启用了错误报告和显示错误,启动错误,并且还可以使用...

ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting( E_ALL | E_STRICT);

...in my code. ...在我的代码中。 But still, no message or error appears for missing extensions. 但是,对于缺少的扩展名,不会显示任何消息或错误。

Isn't PHP 7.2 not able anymore to throw an error, when the function calls missing his necessary extensions? 当函数调用缺少必要的扩展名时,PHP 7.2是否不再会引发错误? Or is there some misconfiguration in the default-settings of the php.ini ? 还是php.ini的默认设置中有一些配置错误?

What do I miss here? 我在这里想念什么?


20181210 20181210

Solution

At the end it was my own fault, I've let my Router-Script try/catch Exceptions and Throwables into an variable, but doesn't dumped or debuged them then. 最后,这是我自己的错,我已经将我的路由器脚本尝试/捕获异常和Throwables到一个变量中,但是那时没有转储或调试它们。 Sorry for the whole hasse 对不起,整个麻烦

Additional important note 附加重要说明

To make sure that I made the issue here comprehensible : I can get error-notices and exceptions for most of the common errors like misspelling a function, wrong syntax, declaration, require, missing-file and so on. 为了确保使我在这里理解的问题是 :对于大多数常见错误,例如拼写错误的函数,错误的语法,声明,require,缺少文件等,我可以得到错误通知和异常。 But my issue here is that PHP 7.2 isn't able to notice that some php-extension is missing and instead to giving some feedback on page or log, it just stops at the function which would/should require the php-extension. 但是我的问题是PHP 7.2无法注意到缺少某些php扩展名,而是在页面或日志上提供了一些反馈,它只是停留在需要php扩展名的功能上。

Are you executing php 7.2 using php-fpm? 您是否正在使用php-fpm执行php 7.2? The php.ini does nothing for php-fpm. php.ini对于php-fpm无效。 In this case you need to update the php-fpm.conf file. 在这种情况下,您需要更新php-fpm.conf文件。

The correct lines for php-fpm are: php-fpm的正确行是:

; enable display of errors
php_flag[display_errors] = on
php_flag[display_startup_errors] = on

Have you tried error_reporting(-1) ? 您是否尝试过error_reporting(-1)

It appears that error_reporting( E_ALL | E_STRICT) does not process all parse/syntax errors. 看来error_reporting( E_ALL | E_STRICT)不能处理所有解析/语法错误。

See for example: 参见例如:

EDIT : To catch errors/exceptions can also be useful (see comments) 编辑:捕获错误/异常也很有用(请参阅评论)

try {
     // Your code
} catch(Throwable $e) {
    echo $e->getMessage();
}

You can catch Error or Throwable (which catches exceptions and errors (> PHP 5)) 您可以捕获ErrorThrowable (捕获异常和错误(> PHP 5))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM