Re: Please save me from insanity - PHP4 / OO

From: Date: Sun, 05 Dec 2004 18:29:31 +0000
Subject: Re: Please save me from insanity - PHP4 / OO
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-203531@lists.php.net to get a copy of this message
Thanks a lot for your responses guys. Unfortunately it still isn't working for me. I've tried both : $ob->prop = &$this and $ob->prop &= $this (just in case) Neither produce a "PHP is OK". I'm using version 4.2.2 btw. (If ONLY I was on 5) Thanks again, Ben Greg Beaver wrote:
Ben wrote:
class Ob {
    var $prop;
} class Test {
    function setMe(&$ob) {
        $ob->prop = $this;
    }
} $ob = new Ob(); $test = new Test(); $test->setMe($ob); if ($ob->prop) error_log("PHP is OK"); else error_log("PHP is a fucking MARE"); What is my problem here? Please help!
You've run into the "I really need PHP5" problem :) <?php class Ob {
    var $prop;
} class Test {
    function setMe(&$obj)
    {
        $ob->prop = &$this; // note another &
    }
} $ob = new Ob; $test = new Test; $test->setMe($ob); if ($ob->prop) {
    error_log("PHP is more than OK");
} else {
    error_log("I forgot the second &");
} ?> Here's your PHP5 version <?php class Ob {
    public $prop;
} class Test {
    public function setMe($obj)
    {
        $obj->prop = $this;
    }
} $ob = new Ob; $test = new Test; $test->setMe($ob); if ($ob->prop) {
    error_log("PHP5 is *way* more than OK");
} else {
    error_log("This can't happen");
} ?> Greg


« previous php.general (#203531) next »