Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

yukilghjgsdy's avatar

Laravel: PHP Deprecation Warning results in Error

Hi,

I'm running Laravel 7.29 on PHP 7.4 and I'm using some legacy code that makes use of PHPs define() in a way that's deprecated now.

Strangely enough, this results in a stacktrace and a fatal error (PHP stops executing and throws an exception):

[2022-05-04 15:17:47] production.ERROR: define(): Declaration of case-insensitive constants is deprecated {"userId":"opsec","exception":"[object] (ErrorException(code: 0): define(): Declaration of case-insensitive constants is deprecated at /path/to/file.php:100)

Any ideas why Laravel seems to stop execution here and throw an error? This should still work without error.

Is there a way to make Laravel not error on warnings?

Thanks!

0 likes
2 replies
kokoshneta's avatar

If your PHP settings are set to throw exceptions (instead of native PHP errors) and your error directives include deprecation warnings, then any use of deprecated code will generate a warning, which will be turned into an ErrorException that gets thrown – and from that point on, it’s just a thrown exception that will halt execution if not caught.

Have a look at what your error_reporting() and display_errors() values are set to. Chances are, they’re set to include notices as well.

yukilghjgsdy's avatar

Hm, my php.ini sets:

error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off

My guess would be that Larvel or some Symfony library overwrites that?

 ~/Sites/opsec-backend [master] > grep -R error_reporting *
vendor/symfony/http-kernel/Kernel.php:        $errorLevel = error_reporting(\E_ALL ^ \E_WARNING);
vendor/symfony/http-kernel/Kernel.php:                error_reporting($errorLevel);
vendor/symfony/http-kernel/Kernel.php:            error_reporting($errorLevel);
vendor/symfony/http-kernel/HttpKernelBrowser.php:        $errorReporting = error_reporting();
vendor/symfony/http-kernel/HttpKernelBrowser.php:error_reporting($errorReporting);
vendor/symfony/error-handler/Debug.php:        error_reporting(-1);
vendor/symfony/error-handler/DebugClassLoader.php:        $e = error_reporting(error_reporting() | \E_PARSE | \E_ERROR | \E_CORE_ERROR | \E_COMPILE_ERROR);
vendor/symfony/error-handler/DebugClassLoader.php:            error_reporting($e);
vendor/symfony/error-handler/ErrorHandler.php:        $level = error_reporting();
vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:        error_reporting(-1);
vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:        if (error_reporting() & $level) {

Please or to participate in this conversation.