moriyoshi               Sun Jan  2 01:51:36 2005 EDT

  Added files:                 (Branch: PHP_5_0)
    /php-src/ext/standard/tests/array   bug29493.phpt bug31213.phpt 
  Log:
  - MFH: add testcases for bug #29493 and #31213.
  
  

http://cvs.php.net/co.php/php-src/ext/standard/tests/array/bug29493.phpt?r=1.1&p=1
Index: php-src/ext/standard/tests/array/bug29493.phpt
+++ php-src/ext/standard/tests/array/bug29493.phpt
--TEST--
Bug #29493 (extract(EXTR_REFS) fails if array has multiple referrals)
--FILE--
<?php
function t1()
{
        $a = array('foo' => 'aaa');
        // refcount($a) = 1
        // refcount($a['foo']) = 1
        $b = $a;
        // refcount($a) = 2
        // refcount($a['foo']) = 1
        $b['foo'] = 'bbb';
        // refcount($a) = 1
        // refcount($a['foo']) = 1

        var_dump($a, $b);

        extract($a, EXTR_REFS);

        $foo = 'noo';

        var_dump($a, $b);
}

function t2()
{
        $a = array('foo' => 'aaa');
        // refcount($a) = 1
        // refcount($a['foo']) = 1
        $b = &$a;
        // refcount($a) = 2
        // is_ref($a) = true
        // refcount($a['foo']) = 1
        $b['foo'] = 'bbb';
        // refcount($a) = 2
        // refcount($a['foo']) = 1

        var_dump($a, $b);

        extract($a, EXTR_REFS);

        $foo = 'noo';

        var_dump($a, $b);
}

function t3()
{
        $a = array('foo' => 'aaa');
        // refcount($a) = 1
        // refcount($a['foo']) = 1
        $b = &$a;
        // refcount($a) = 2
        // is_ref($a) = true
        // refcount($a['foo']) = 1
        unset($b);
        // refcount($a) = 1
        // is_ref($a) = true
        // refcount($a['foo']) = 1

        var_dump($a);

        extract($a, EXTR_REFS);

        $foo = 'noo';

        var_dump($a);
}

t1();
t2();
t3();
?>
--EXPECT--
array(1) {
  ["foo"]=>
  string(3) "aaa"
}
array(1) {
  ["foo"]=>
  string(3) "bbb"
}
array(1) {
  ["foo"]=>
  &string(3) "noo"
}
array(1) {
  ["foo"]=>
  string(3) "bbb"
}
array(1) {
  ["foo"]=>
  string(3) "bbb"
}
array(1) {
  ["foo"]=>
  string(3) "bbb"
}
array(1) {
  ["foo"]=>
  &string(3) "noo"
}
array(1) {
  ["foo"]=>
  &string(3) "noo"
}
array(1) {
  ["foo"]=>
  string(3) "aaa"
}
array(1) {
  ["foo"]=>
  &string(3) "noo"
}

http://cvs.php.net/co.php/php-src/ext/standard/tests/array/bug31213.phpt?r=1.1&p=1
Index: php-src/ext/standard/tests/array/bug31213.phpt
+++ php-src/ext/standard/tests/array/bug31213.phpt
--TEST--
Bug #31213 (Sideeffects caused by bug #29493)
--FILE--
<?php
function test($use_extract) {
        $a = 1;
        $b = 1;

        $arr = array(
                '_a' => $a,
                '_b' => &$b
        );

        var_dump($a, $b);

        if ($use_extract) {
                extract($arr, EXTR_REFS);
        } else {
                $_a = &$arr['_a'];
                $_b = &$arr['_b'];
        }

        $_a++;
        $_b++;

        var_dump($a, $b, $_a, $_b, $arr);
}

test(false);
test(true);
--EXPECT--
int(1)
int(1)
int(1)
int(2)
int(2)
int(2)
array(2) {
  ["_a"]=>
  &int(2)
  ["_b"]=>
  &int(2)
}
int(1)
int(1)
int(1)
int(2)
int(2)
int(2)
array(2) {
  ["_a"]=>
  &int(2)
  ["_b"]=>
  &int(2)
}

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to