php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34752 foreach seam to overwrite values
Submitted: 2005-10-06 10:58 UTC Modified: 2005-10-31 14:01 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: trash at jennyfm dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.5 OS: linux 2.6.13
Private report: No CVE-ID: None
 [2005-10-06 10:58 UTC] trash at jennyfm dot net
Description:
------------
foreach seam to overwrite values in array ..... 
it works fine in 5.0.4 but in 5.0.5 not.
don't know why...

Reproduce code:
---------------
full class source here: http://kuerbis.org/template/show_source.php
class Template extends KTemplate {
...........
  protected function _initTemplate()
        {
            parent::_initTemplate();
            if (isset($this->bl) && is_array($this->bl))
            {
            print_r($this->bl);
            //before foreach bl is ok in 5.0.4 and 5.0.5
                foreach ($this->bl as $key => $value)
                {
                    $this->blc[$key] = true;
                }
            //after foreach bl is overwritten in 5.0.5, in 5.0.4 it works
            print_r($this->bl);
            }
        }
......
}

Expected result:
----------------
in php 5.0.4 i get (after the foreach)
.......
Array
(
    [mainmenu] => KTemplateExt Object
        (
            [removeEmptyBlocks] => 1
            [delimiterStart:protected] => {
            [delimiterEnd:protected] => }
            [t:protected] =>                
                        {menu_title}

            [pl:protected] => 
            [bl:protected] => 
            [templatefile:protected] => 
            [className:protected] => KTemplateExt
            [params] => 
        )

)
.... and so on

Actual result:
--------------
in php 5.0.5 i get (after the foreach)

(
    [menublock] => Array
        (
            [menublock] => 1
            [not_logged_in] => 1
            [logged_in] => 1
        )

    [not_logged_in] => 1
    [logged_in] => 1
)

.... and so on

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-06 11:11 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2005-10-06 13:35 UTC] trash at jennyfm dot net
The main script is here (with wrong result in php 5.0.5):
wp1011644.wp021.webpack.hosteurope.de/muellercms/test.php
source:
wp1011644.wp021.webpack.hosteurope.de/muellercms/test.php_
wp1011644.wp021.webpack.hosteurope.de/muellercms/include/function_template5.inc.php_
wp1011644.wp021.webpack.hosteurope.de/muellercms/include/function_templateext5.inc.php_
template file (not relevant):
wp1011644.wp021.webpack.hosteurope.de/muellercms/templates/test.tpl_

The error seems to be in function_templateext5::_initTemplate after the foreach print_r($this->bl) returns overwritten result. In php 5.0.4 the result looks like:
Array
(
    [testsub] => PDTemplateExt Object
        (   [removeEmptyBlocks] => 1
            [delimiterStart:protected] => {
            [delimiterEnd:protected] => }
            [t:protected] => )..........
test
buii 
before the foreach the $test->bl seems to be ok in both versions(5.0.4 and 5.0.5). Same problem i have with while (list ($key, $value) = each ($this->bl)), in 5.0.4 it works and in 5.0.5 not. Server config is here wp1011644.wp021.webpack.hosteurope.de/phpinfo.php
 [2005-10-06 13:40 UTC] tony2001@php.net
I was asking about a SHORT reproduce script.
Those scripts are definitely not short.
All those classes and other stuff have nothing to do with `foreach`.
 [2005-10-06 15:23 UTC] trash at jennyfm dot net
hmmpf ;D hope this is short enough

<?php
echo "<pre>";
class Test{

    protected $blc;
    protected $bl;

public function test2 (){

    $this->bl['0'] =& new $this;
    $this->bl['1'] =&new  $this;

    print_r($this->bl);
    foreach ($this->bl as $key => $value){

        $this->blc[$key] =true;
    }
    //here it returns wrong bl in 5.0.5, in <=5.0.4 it works fine
    print_r($this->bl);
}
}
$buii = new Test();
$buii->test2();
echo "</pre>";
?>
 [2005-10-06 15:33 UTC] tony2001@php.net
"Returns wrong" ?
What's the expected result, what's the actual result you get?

This is what I got with 5.0.6-dev:
Array
(
    [0] => Test Object
        (
            [blc:protected] =>
            [bl:protected] =>
        )

    [1] => Test Object
        (
            [blc:protected] =>
            [bl:protected] =>
        )

)
Array
(
    [0] => Test Object
        (
            [blc:protected] =>
            [bl:protected] =>
        )

    [1] => Test Object
        (
            [blc:protected] =>
            [bl:protected] =>
        )

)
Is this "wrong" or "right" ?
 [2005-10-06 15:35 UTC] trash at jennyfm dot net
right.... 

this is my result. 
http://wp1011644.wp021.webpack.hosteurope.de/muellercms/buii.php
 [2005-10-14 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2005-10-31 13:55 UTC] trash at jennyfm dot net
the problem caused of Zend Optimizer v2.5.10,
in 2.5.8 it works fine.
 [2005-10-31 14:01 UTC] derick@php.net
Do not file bugs when you have Zend extensions (zend_extension=)
loaded. Examples are Zend Optimizer, Zend Debugger, Turck MM Cache,
APC, Xdebug and ionCube loader.  These extensions often modify engine
behavior which is not related to PHP itself.

Report those bugs with the Zend team.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 07 23:01:32 2025 UTC