|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-03-21 15:50 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 04:00:02 2025 UTC |
I think I could isolate the bug. Check the following code: <?php class crash { protected $array; protected $mem; function nothing() { $this->array = new ArrayObject(); $this->mem = new ArrayObject(); $this->mem['empty'] = new ArrayObject(); } function __get($field) { $field = strtolower($field); return $this->array[$field]; } function test() { if ($this->mem['empty']['crash']) return true; return false; } } $crash = new crash(); $crash->break_mem['here0'] = 'This is to break.'; $crash->break_mem['here1'] = 'This is to break.'; $crash->break_mem['here2'] = 'This is to break.'; $crash->break_mem['here3'] = 'This is to break.'; $crash->break_mem['here4'] = 'This is to break.'; if ($crash->test()) echo 'BUUUMMMMM!'; ?> This code should show nothing, but it showed BUUUMMMM! here. If you cannot make it show BUM, increase the number of calls to $crash->break_mem['here4'] = 'This is to break.'; Hope that is enough