I have the following PHP code:

$TBL_PREFIX="tbl_calendar";
$OTHERTBL_PREFIX="tbl_calendar_other
";

class Editor{
var $TBL;
var $OTHERTBL;

function Editor(){
global $TBL_PREFIX;
global $OTHERTBL_PREFIX;

$this->$TBL=$TBL_PREFIX;
$this->$OTHERTBL=$OTHERTBL_PREFIX;

}

function getIncomingEventList(){
$sql="select e.id,e.event_name,e.date_created from ".$this->$TBL."event e
join ".$this->$TBL."status s on e.status_id=s.id where e.status_id=1";
$rs=mysql_query($sql) or Error::handleQueryError($sql);

return $this->toArray($rs);

}
}

Here's what's weird: debugging shows that in function getIncomingEventList, $this->$TBL has a value equivilent to $OTHERTBL_PREFIX. If I delete or comment out the line $this->$OTHERTBL=$OTHERTBL_PREFIX, $this->$TBL asssumes the value of $TBL_PREFIX.

Why is that happening and what can I do to fix it? I have PHP4 with Apache2.

    In other words, given the following code:

    $thum="hmmmmm";
    $otherthum="yam";

    class Boo{
    var $hum;
    var $otherhum;

    function Boo(){
    global $thum;
    global $otherthum;

    $this->$hum=$thum;
    $this->$otherhum=$otherthum;

    }
    function Booya(){
    echo $this->$hum;
    echo "<br/>";
    echo $this->$otherhum;
    }
    }

    $Boo=new Boo;
    $Boo->Booya();

    the word "yam" is displayed twice. Why?

      Reference the class attributes as $this->TBL, not $this->$TBL.

        Write a Reply...