|  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 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 !
Your email address:
Solve the problem:
15 + 28 = ?
Subscribe to this entry?

 [2013-06-01 15:23 UTC] matteosistisette at gmail dot com
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:
$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 

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-02 01:01 UTC]
-Status: Open +Status: Not a bug
 [2013-06-02 01:01 UTC]
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]
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-2023 The PHP Group
All rights reserved.
Last updated: Thu Nov 30 12:01:25 2023 UTC