View Single Post
Old 07-13-2008, 10:13 PM   #3 (permalink)
delayedinsanity
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Quote:
Now your assignments above can actually place these variables, and if you wanted to access what you recently put through the last function call:
Actually, since PHP supports dynamic properties, once they are set, they are accessible either way. So you don't necessarily have to define every property you plan on using, it's just good practice. Take the following for example;

PHP Code:
class var_test
{

    public function 
set ($x$y)
    {
        
$this->$x;
        
$this->$y;
    }

    public function 
show ()
    {
        echo 
'X: <strong>',$this->x,'</strong><br />';
        echo 
'Y: <strong>',$this->y,'</strong><br />';
    }

    public function 
add ()
    {
        echo 
$this->x,'+',$this->y,'=',$this->x+$this->y;
    }

};

$pTest = new var_test;
$pTest->show();
$pTest->set(1010);
$pTest->show();
$pTest->add();
echo 
'<br />',$pTest->x
The first call to show() will return Notice: Undefined property: var_test::$x in...but the second time it works as the properties have been set, even though they were not laid out in the class.
-m
delayedinsanity is offline  
Reply With Quote