php-src icon indicating copy to clipboard operation
php-src copied to clipboard

Could not catch deprecation notice from IntlDateFormatter()

Open xmav opened this issue 4 years ago • 1 comments

Description

The following code:

error_reporting(E_ALL);
set_error_handler(function ($errNo, $errStr) {echo 'Handle ' . $errStr;});
str_contains("test", null);
new \IntlDateFormatter('en_US', 0, null);
<?php

Resulted in this output:

Handle str_contains(): Passing null to parameter #2 ($needle) of type string is deprecated
PHP Deprecated:  IntlDateFormatter::__construct(): Passing null to parameter #3 ($timeType) of type int is deprecated in dep.php on line 5
Deprecated: IntlDateFormatter::__construct(): Passing null to parameter #3 ($timeType) of type int is deprecated in dep.php on line 5

But I expected this output instead:

Handle str_contains(): Passing null to parameter #2 ($needle) of type string is deprecated
Handle IntlDateFormatter::__construct(): Passing null to parameter #3 ($timeType) of type int is deprecated in dep.php on line 5

PHP Version

PHP 8.1.0

Operating System

No response

xmav avatar Feb 18 '22 03:02 xmav

The problem occurs here:

https://github.com/php/php-src/blob/90e4d5456b393a692d4de751561b349d4a9e7b88/ext/intl/dateformat/dateformat_create.cpp#L204-L208

Arguments are parsed in datefmt_ctor but zend_replace_error_handling replaces the error handler before that. Usually zend_replace_error_handling is only called after arguments are already parsed.

iluuu1994 avatar Feb 18 '22 09:02 iluuu1994