From:             profic at kursknet dot ru
Operating system: WinXP
PHP version:      5.0.2
PHP Bug Type:     Zend Engine 2 problem
Bug description:  arrayAcces & using $this

Description:
------------
Class inherited of class implemented ArrayAccess have problems with using
$this['some' . $var] = $var . 'str';
if $var passed as method parameter.
Seems this is a memory problem.
Look at the 3 last entries in rtfHelperArray::haStore.

Reproduce code:
---------------
<?php
abstract class rtfHelperArray implements arrayAccess {
        private $haStore = array ();

        final public function offsetExists ($offset) {
                return true;
        }

        final public function offsetGet ($offset) {
                if (array_key_exists ($offset, $this->haStore)) {
                        return $this->haStore[$offset];
                } else {
                        $temp = NULL;
                        return $temp;
                }
        }

        final public function offsetSet ($offset, $value) {
                $this->haStore[$offset] = $value;
                return true;
        }

        final public function offsetUnset ($offset) {
                unset ($this->haStore[$offset]);
                return true;
        }
}

error_reporting (E_ALL);

class test extends rtfHelperArray {
        public function doTest ($idx) {
                $this[$idx] = $idx;
                echo $idx, ' : ', $this[$idx], "\n";
                $this[$idx . '-2'] = $idx . '-2';
                echo $idx . '-2', ' : ', $this[$idx . '-2'], "\n";
                $this['3-' . $idx] = $idx . '-333';
                echo '3-' . $idx, ' : ', $this['3-' . $idx], "\n";
                $this['4-' . $idx] = $idx . '-4444';
                echo '4-' . $idx, ' : ', $this['4-' . $idx], "\n";
                $this['5-' . $idx] = $idx . '-5';
                echo '5-' . $idx, ' : ', $this['5-' . $idx], "\n";
                var_dump ($this);
        }
}

$o = new test ();
$o->doTest ('idx');
?>

Expected result:
----------------
idx : idx
idx-2 : idx-2
3-idx : idx-333
4-idx : idx-4444
5-idx : idx-5
object(test)#1 (1) {
  ["haStore:private"]=>
  array(5) {
    ["idx"]=>
    string(3) "idx"
    ["idx-2"]=>
    string(5) "idx-2"
    ["3-idx"]=>
    string(7) "idx-333"
    ["4-idx"]=>
    string(8) "idx-4444"
    ["5-idx"]=>
    string(5) "idx-5"
  }
}

Actual result:
--------------
idx : idx
idx-2 : idx-2
3-idx :
4-idx : idx-4444
5-idx :
object(test)#1 (1) {
  ["haStore:private"]=>
  array(5) {
    ["idx"]=>
    string(3) "idx"
    ["idx-2"]=>
    string(5) "idx-2"
    ["idx-3"]=>
    string(7) "test  3"
    ["4-idx"]=>
    string(8) "idx-4444"
    ["idx-5"]=>
    string(5) "test "
  }
}

-- 
Edit bug report at http://bugs.php.net/?id=30346&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=30346&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30346&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30346&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=30346&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=30346&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=30346&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=30346&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=30346&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=30346&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=30346&r=notwrong
Not enough info:             http://bugs.php.net/fix.php?id=30346&r=notenoughinfo
Submitted twice:             http://bugs.php.net/fix.php?id=30346&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=30346&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=30346&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=30346&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=30346&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=30346&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=30346&r=float
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=30346&r=mysqlcfg

Reply via email to