php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64955 "array to string conversion" notice should contain more information
Submitted: 2013-06-01 15:23 UTC Modified: 2013-06-02 11:49 UTC
From: matteosistisette at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.4.15 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: matteosistisette at gmail dot com
New email:
PHP Version: OS:

 

 [2013-06-01 15:23 UTC] matteosistisette at gmail dot com
Description:
------------
The "Array to string conversion" notice message should at the very least include 
the name of the array variable that is being converted to string.

A line of code may contain a lot of variables, so figuring out which one is the 
unexpected array can be a pain in the ass.

Even the backtrace won't contain enough information since it only gives the line 
but not the position within the line.

Test script:
---------------
$string1="foo";
$string2="bar";
$string3=array("Whoops, this is an array");
$string4="bla bla";

echo $string1.$string2.$string3.$string4.

Expected result:
----------------
PHP NOTICE at /path/to/file.php (6): Array to string conversion for variable 
'string3'

Actual result:
--------------
PHP NOTICE at /path/to/file.php (6): Array to string conversion

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-02 01:01 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2013-06-02 01:01 UTC] rasmus@php.net
That's actually surprisingly difficult to do given how bison (the parser 
generator) works. You can do it quite easily in userspace though. Just break up 
the line you are having trouble with over multiple lines and the line number will 
tell you which variable it is.
 [2013-06-02 11:49 UTC] matteosistisette at gmail dot com
Ok. The correct status would be "won't fix", however.

This is a more general issue, actually. It applies to most error messages. Line 
number is often not enough, and having to split a line of code into multiple 
lines every time you have to debug an error (and then, get them back to one line 
so the code doesn't become unreadable) is definitely not viable.
 [2013-06-02 12:23 UTC] nikic@php.net
This is not just difficult, this is to the most part impossible. In this particular case where the array->string conversion happens to be the result of a concatenation of variables, sure, one could in theory (with a sufficient amount of special casing) give you a variable name.

But usually this is not the case. Instead the error happens as part of some other operation or using the result of some other operation. This particular notice for example often occurs inside functions like array_diff. There is no responsible "variable name" in such cases.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC