Bug #81591 [NEW]: Fatal Error not properly logged in particular cases

From: Date: Thu, 04 Nov 2021 14:15:48 +0000
Subject: Bug #81591 [NEW]: Fatal Error not properly logged in particular cases
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237552@lists.php.net to get a copy of this message
From:             anton at cpp dot in
Operating system: FreeBSD 12.3
PHP version:      8.0.12
Package:          *General Issues
Bug Type:         Bug
Bug description:Fatal Error not properly logged in particular cases

Description:
------------
We had a few 500 pages without any traces in php.log after updating from
7.4 to 8.0.

The reason was a parameter type mismatch of in_array and
array_key_exists functions, but TypeError was not logged if a warning
previously occurred at the same line.

We had these warnings silenced with @$_REQUEST['whatever'], so no log
messages were produced as a result of the crash.

While this pattern is ugly and should be refactored with proper checking
and casting (and it was), I believe TypeError should be generated and
properly logged in this case nonetheless.


Test script:
---------------
<?php

error_reporting(E_ALL);

$not_array = false;

// Case #1, incorrect: only 'PHP Warning:  Undefined array key
"nonexistant"' is logged
echo (array_key_exists($_REQUEST['nonexistant'], $not_array) ? "yes" :
"no");

// Case #2, correct: 'PHP Fatal error:  Uncaught TypeError:
array_key_exists(): Argument #2 ($array) must be of type array, bool
given' is logged
$nonexistant = NULL;
echo (array_key_exists($nonexistant, $not_array) ? "yes" : "no");

// Case #3, correct: both Warning and Fatal error are logged
function my_ake(string|int $key, array $array): bool {return
array_key_exists($key, $array);}
echo (my_ake($_REQUEST['nonexistant'], $not_array) ? "yes" : "no");



-- 
Edit bug report at https://bugs.php.net/bug.php?id=81591&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=81591&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=81591&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=81591&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=81591&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=81591&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=81591&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=81591&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=81591&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=81591&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=81591&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81591&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=81591&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=81591&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=81591&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=81591&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=81591&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=81591&r=mysqlcfg


Thread (6 messages)

« previous php.bugs (#237552) next »