|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #77981 "Undefined offset" notice must include name of variable in ERROR LOG message
Submitted: 2019-05-07 11:33 UTC Modified: 2021-07-28 10:12 UTC
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: forkik at gmail dot com Assigned: cmb (profile)
Status: Wont fix Package: *General Issues
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
24 - 14 = ?
Subscribe to this entry?

 [2019-05-07 11:33 UTC] forkik at gmail dot com
Very important to know (from log) and to log in which variable (name of the variable) error like "NOTICE (Undefined offset: 1)" occurred! Still it is NOT POSSIBLE!

This is important when one of these situations occur (the more situations occurred the more difficult to detect the exact variable (name)):
1. code changes rapidly (so error line can even mislead without variable name); 
2. variables data is from database (and database changes rapidly in big database so it is impossible to detect in which variable name);
3. there are multiple variables in the same line.

Test script:
$A = [1 => ''];
$B = [1 => ''];
$X_variable_name = [];

function log_handler ( $errno, $errstr,  $errfile, $errline, $errcontext ) {
	$bt = debug_backtrace();
	$bt0 = (isset($bt[0]) && isset($bt[0]['file']) ? basename(dirname($bt[0]['file'])).'/'.basename($bt[0]['file']).':'.$bt[0]['line'] : '');
	$bt1 = (isset($bt[1]) ? basename(dirname($bt[1]['file'])).'/'.basename($bt[1]['file']).':'.$bt[1]['line'] : '');
	$bt2 = (isset($bt[2]) ? basename(dirname($bt[2]['file'])).'/'.basename($bt[2]['file']).':'.$bt[2]['line'] : '');
	echo date("y-m-d H:i:s").' '.$errorType[$errno]." ($errstr) ".$errfile.":$errline "./*print_r($errcontext, true).*/' '.$bt0.' 1:'.$bt1.' 2:'.$bt2."\n";
echo $A[1].$B[1].$X_variable_name[1];

Expected result:
19-05-07 14:07:06 NOTICE (Undefined offset: 1 in variable: X_variable_name) /home/tests/php/error_log.php:65  php/error_log.php:65 1: 2:

Actual result:
19-05-07 14:07:06 NOTICE (Undefined offset: 1) /home/tests/php/error_log.php:65  php/error_log.php:65 1: 2:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-05-07 11:58 UTC]
-Summary: Missing very important variable name in error logging (core) +Summary: "Undefined offset" notice should include name of variable in message -Type: Bug +Type: Feature/Change Request
 [2019-05-07 12:01 UTC]
-Package: Reproducible crash +Package: *General Issues
 [2019-05-09 13:01 UTC] forkik at gmail dot com
-Summary: "Undefined offset" notice should include name of variable in message +Summary: "Undefined offset" notice must include name of variable in ERROR LOG message
 [2019-05-09 13:01 UTC] forkik at gmail dot com
 [2021-07-28 10:12 UTC]
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-07-28 10:12 UTC]
There is no guarantee that there is a variable name involded, e.g.
timezone_identifiers_list()[42].  And actually, the notice is
about a *value*, not a *variable*.

If you still think this should be improved, please pursue the RFC

[1] <>
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Sep 19 03:03:37 2021 UTC