Hello,

I'm getting a problem with $this being defined where it shouldn't be. The code
that I'm writing is a little weird in order to compensate for the lack of some
OO features in PHP4.

The PHP script at the bottom should give the behavior I'm referring to.

Is PHP5 in a more-or-less stable state? Are PHP4 extensions completely
compatible with PHP5?

Josh

<?php

/* No static attributes in PHP4. */
$static_class1=NULL;

class Class1{
    var $var1;
    function Class1(){ $this->var1=0; }

    function init(){
        global $static_class1;
        $static_class1 = new Class1();
    }

    function getVar(){
        /* Check for $this. This is a way of making a static method 
           and a regular method with the same name. */
        /* $this is defined here directly after called from the
           Class2 constructor. */
        if(isset($this)){
            return $this->var1;
        } else {
            global $static_class1;
            $static_class1->getVar();
        }
    }
}

class Class2{
    function Class2(){
        $a=Class1::getVar();
    }
}

Class1::init();
$a=new Class2();

?>


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to