Hi,
I've discovered strange behavior of PHP. The following script has no sense
and value,
it is simplified due to clearness. The output of the script should be (in my
opinion):

class A2<br>
class A1<br>

But it isn't (using PHP 4.3.4). The problem arise, when the Callback
function of a1
object calls GetOtherCnt. There, only a1 object is valid but not a2 although
it should be.
So, the output is:

<br>
class A1<br>

It works, if the a1->Init() call is performed after creating the a2 object.
And in my
real script no replacing of this call helps. It is not clear to me why it
happens so.
What do You think about it? Have You any explanation for that?

Thanks for answers,
Mike

Here is the script:

<?

class A
{
    var $control_class = FALSE;
    var $cnt = "";

    function Init($control_class)
    {
        $this->control_class = $control_class;
    }

    function Callback()
    {
        return $this->control_class->GetOtherCnt($this->cnt);
    }
}

class A1 extends A
{
    var $cnt = "class A1";
}

class A2 extends A
{
    var $cnt = "class A2";
}

class Control
{
    var $a1 = FALSE;
    var $a2 = FALSE;

    function Init()
    {
        $this->a1 = new A1();
        $this->a1->Init($this);

        $this->a2 = new A2();
        $this->a2->Init($this);
    }

    function PrintIt()
    {
        echo $this->a1->Callback() . "<br>";
        echo $this->a2->Callback() . "<br>";
    }

    function GetOtherCnt($cnt)
    {
        if($cnt == $this->a1->cnt)
            return $this->a2->cnt;
        if($cnt == $this->a2->cnt)
            return $this->a1->cnt;
        return "";
    }
}

$test = new Control();
$test->Init();

$test->PrintIt();

?>

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

Reply via email to