php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #37259 Bad error message for ArrayAccess return by reference
Submitted: 2006-05-01 14:49 UTC Modified: 2006-05-01 16:17 UTC
From: tbarstow at workflowbydesign dot com Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 5.* OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2006-05-01 14:49 UTC] tbarstow at workflowbydesign dot com
Description:
------------
This is related to the issue with ArrayAccess not being able to return by reference. See:
http://bugs.php.net/bug.php?id=32983
http://bugs.php.net/bug.php?id=34783

However this is NOT a re-post of the above referenced bug.  Rather, I am reporting a bug that relates to the error message that results from this situation.

The error message reads: "Objects used as arrays in post/pre increment/decrement must return values by reference". 

Two issues with this:

1. It's not possible to do.  "Objects used as arrays" cannot return values by reference, as noted in the bugs referenced above.
2. This doesn't only happen in post/pre increment/decrement cases.  There are a couple of examples in the bugs linked above; others exist as well (consider passing $array_access_object['foo'] to a function that takes a reference, for example).




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-01 15:37 UTC] helly@php.net
We cannot change this. We could only probably add something more, a new additiona? inteface that can only deal with references. ...We coukd but we don't.
 [2006-05-01 15:44 UTC] tbarstow at workflowbydesign dot com
You didn't really read my bug report.  This is a report about a PHP generated error message, not the fact that ArrayAccess can't deal with returning references.  Please re-open the bug or provide a response that actually relates to the bug I am reporting.
 [2006-05-01 16:11 UTC] helly@php.net
Seems you are missing your own point. The error message and all related is all based on the fact that ArrayAccess protocol (member function signatures) are not capeable of handling references.
 [2006-05-01 16:17 UTC] tbarstow at workflowbydesign dot com
Not really missing my own point.  There are two points, neither of which is addressed:

1. The error message seems to be instructive (perhaps this is a language barrier issue).  It seems to say (to me, anyway), "go and rewrite your array access object to return by reference", which as we both know is impossible.
2. The error message indicates that it is being thrown because of a particular situation--pre/post increment/decrement--when in fact it can occur when there is no increment/decrement happening at all.

The point is: this is a very confusing error message, and though I have not inspected how error messages get generated by PHP, I am willing to bet that this would be a very simple thing to change and thus make it easier for PHP developers to understand what's going on (and perhaps not post duplicate bugs about this over and over again).

Anyway thanks for your time.  PHP is great, and I love the SPL in general.  I just wish there were some elegant way to use ArrayAccess in pass-by-reference situations.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 20:01:29 2024 UTC