Req #38118 [Opn]: unrelated error when using reference

From: Date: Sun, 20 Mar 2016 13:06:35 +0000
Subject: Req #38118 [Opn]: unrelated error when using reference
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199963@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=38118&edit=1

 ID:                 38118
 Updated by:         nikic@php.net
 Reported by:        public at grik dot net
 Summary:            unrelated error when using reference
 Status:             Open
 Type:               Feature/Change Request
-Package:            Feature/Change Request
+Package:            *General Issues
 Operating System:   *
 PHP Version:        5.2.0
 Block user comment: N
 Private report:     N

 New Comment:

The error message has been changed to refer to "indirect modification" in 5.2.1, see https://3v4l.org/upViG.

Nowadays it is also possible to return by reference from offsetGet, in which case this code is
allowed: https://3v4l.org/muTTS

However, the assignment has no reference-breaking semantics.


Previous Comments:
------------------------------------------------------------------------
[2006-07-24 00:00:23] public at grik dot net

exactly the same error

[root@demo www]# php -v
PHP 5.2.0-dev (cli) (built: Jul 24 2006 02:54:55)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2006 Zend Technologies
[root@demo www]# php test.php

Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference
in /www/test.php on line 27

------------------------------------------------------------------------
[2006-07-17 06:36:04] tony2001@php.net

Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip



------------------------------------------------------------------------
[2006-07-17 00:42:47] public at grik dot net

Thank you.

The problem of using reference in ArrayAccess class is pure practical. 
I have a set of rules and data fields - each field should be checked against it's rule (e.g.
min, max).
I write the hierarchy of classes implementing the exact logic for each rule. The class instance
should get the set of rule parameters and the data reference.
Then I interate over the management object (extends ArrayObject) with foreach and get the checking
object as a value.

As result, I can make the rules to check the data regardless of it's type and source - scalar,
array, resource. All I need is to write another class with the check logic.

The data may be large, and inability to use references may lead either to
- memory overconsumption 
- DDOS-insecure issue 
- having to refuse from abstration and write more code

------------------------------------------------------------------------
[2006-07-16 23:55:43] helly@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

The '&' is because of inhereitance rules.

The second thing you encounter, the '&=' is an engine limitation.

Btw, both are pure engine issues, nothing todo with SPL.

Maybe you want this reopened as feature request. But then i suggest you provide at least some ideas
where and how to document that ArayAccess cannot be used in modifying operators like
'&='.

Either way you should try 5.2/HEAD first as we've put some work to get you a better error
message.

------------------------------------------------------------------------
[2006-07-16 23:43:09] public at grik dot net

P.S.
I am not allowed to define function offsetGet($key)as 
"function &offsetGet($key){...}"
to return the value by reference due to the requirements of the ArrayAccess interface.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=38118


--
Edit this bug report at https://bugs.php.net/bug.php?id=38118&edit=1


Thread (7 messages)

« previous php.bugs (#199963) next »