#36814 [Bgs->Opn]: ArrayObject is leaking. Seems that OffsetGet should use OffsetExists
ID: 36814
User updated by: raphaelpereira at gmail dot com
Reported By: raphaelpereira at gmail dot com
-Status: Bogus
+Status: Open
Bug Type: SPL related
Operating System: *
PHP Version: *
Assigned To: helly
New Comment:
So, you are telling me (and everybody that uses PHP) that in the
following code:
$a = new ArrayObject();
$a['some'] = new ArrayObject();
if ($a['some']['not_set'])
echo 'Crash!';
else
echo 'Ok';
I cannot expect the answer 'Ok'?
Because my code is doing exactly that, but with more complex code
before the check, none of them touching the ArrayObject in question.
I reopened the bug because this IS a bug. Even if I'm not using the
code correctly, memory is leaking and PHP should not leak, I suppose.
Previous Comments:
------------------------------------------------------------------------
[2006-03-21 16:50:56] 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
There is no need for offsetGet to first call offsetExists from an
engine point of view. If there is a need for this it is either a
problem in the way you either overload ArrayObject/ArrayIterator or use
them.
Unless you can provide code that demonstrates an issue in ArrayObject
itself i assume there is a problem in usage.
Maybe you should note that offsetExists indeed always checks for pure
existance rather than working like empty() or isset() do. Even if
invoked by them.
------------------------------------------------------------------------
[2006-03-21 15:50:41] raphaelpereira at gmail dot com
Description:
------------
My code is very complex and I could not reproduce the bug in another
code, but the issue is that it seems that ArrayObject::offsetGet
doesn't check if the key exists to return it and in some very specific
case this returns invalid results.
The problem is in my query_constraints class. On its constructor I
declare:
class query_constraints
{
protected $_dados;
public function __construct ($params=null)
{
$this->_dados = new ArrayObject();
$this->_dados['in'] = new ArrayObject();
$this->_dados['eq'] = new ArrayObject();
...
Later on I have:
public function equal($campo, $valor)
{
if (!$this->_dados['eq'][$campo] &&
!$this->_dados['in'][$campo])
{
...
Both tests returns false on the first call to this method just after
object construction.
To workaroud the problem I substituted all references to ArrayObject in
this class with the following class:
class ArrayObject1 extends ArrayObject
{
public function offsetget($key)
{
if ($this->offsetexists($key))
return parent::offsetget($key);
return null;
}
}
This solved my problem.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=36814&edit=1
Thread (6 messages)