Hello.

I'm new to this list, and I once looked over the archives,
but the problem like this might not have been proposed, so I ask...

please see the code below
sorry to be too long.

(the result of this code is supposed to be seen with HTML browser)
--------------------------------------------------------------------
<?php
        class foo
        {
                var $cls;

                function foo() {
                        $this->cls = array();
                }
                function add( $cls ) {
                        array_push ( $this->cls, $cls );
                }
                function one() {
                        reset( $this->cls );
                        while( $obj = current( $this->cls ) ) {
                                print '<B>foo->one()</B> invokes <B>'.get_class( $obj 
)."->one()</B><BR>\n";
                                $obj->one();
                                next( $this->cls );
                        }
                }
                function two() {
                        reset( $this->cls );
                        while( $obj = current( $this->cls ) ) {
                                print '<B>foo->two()</B> invokes <B>'.get_class( $obj 
)."->two()</B><BR>\n";
                                $obj->two();
                                next( $this->cls );
                        }
                }
        }

        class bar
        {
                var $some;
                function bar() {
                        $this->some = '<FONT color="red">set in constructor</FONT> ( 
this value was expected to be changed at foo->one() ) ';
                }
                function one() {
                        $this->some = 'modified';
                }
                function two() {
                        print '<B>bar->two->some</B> = '.$this->some."<BR>";
                }
        }

        $fubar = new foo();
        $fubar->add( new bar() );
        $fubar->add( new bar() );
        $foo = new foo();
        $foo->add( $fubar );

        $foo->one();
        $foo->two();
?>
--------------------------------------------------------------------
and the results should have been like 
--------------------------------------------------------------------
foo->one() invokes foo->one()
foo->one() invokes bar->one()
foo->one() invokes bar->one()
foo->two() invokes foo->two()
foo->two() invokes bar->two()
bar->two->some = modified
foo->two() invokes bar->two()
bar->two->some = modified
--------------------------------------------------------------------
but you probably obtain
--------------------------------------------------------------------
foo->one() invokes foo->one()
foo->one() invokes bar->one()
foo->one() invokes bar->one()
foo->two() invokes foo->two()
foo->two() invokes bar->two()
bar->two->some = set in constructor ( this value was expected to be changed at 
foo->one() ) 
foo->two() invokes bar->two()
bar->two->some = set in constructor ( this value was expected to be changed at 
foo->one() )
--------------------------------------------------------------------



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to