From:             vidmich at gmail dot com
Operating system: Windows
PHP version:      5.2.5
PHP Bug Type:     Scripting Engine problem
Bug description:  Assign by reference bug

Description:
------------
Recently I came across a bug in my work with Zend Framework linked with
Smarty. In my investigation I found strange feature of PHP about creation
new element in array if we assign by ref some undefined index from it 
(ZEND_FETCH_DIM_W implementation). For example:

$a = array();
$b =& $a['test’];

After this code array $a will get new element indexed as “test” and
pointing to NULL. This is strange and I didn’t find documentation for this,
but this is rather a feature than a bug.

But I found situation in which above code return _different_ result, which
is really bad and breaks Smarty plugins loading. This situation happened
when we return undefined field in count function in Countable object. For
example

class Test implements Countable
{
  public function count()
  {
    return $this->test;
  }
}

In my opinion calling count on such object (object of class Test) break
global variable in Zend Engine named “uninitialized_zval” and as a result
new created elements point to int(0) instead of NULL

Please make this feature more predictable


Reproduce code:
---------------
<?php

class Test implements Countable
{
    public function count()
    {
        return $this->some;
    }
}

$obj = new Test();

$a = array();
$b =& $a['test'];
var_dump($a);

$t = count($obj);

$a = array();
$b =& $a['test'];
var_dump($a);


Expected result:
----------------
array(1) {
  ["test"]=>
  &NULL
}

array(1) {
  ["test"]=>
  &NULL
}


Actual result:
--------------
array(1) {
  ["test"]=>
  &NULL
}

array(1) {
  ["test"]=>
  &int(0)
}


-- 
Edit bug report at http://bugs.php.net/?id=43505&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=43505&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=43505&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=43505&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=43505&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=43505&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=43505&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=43505&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=43505&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=43505&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=43505&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=43505&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=43505&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=43505&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=43505&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=43505&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=43505&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=43505&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=43505&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=43505&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=43505&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=43505&r=mysqlcfg

Reply via email to