Page 1 of 1

Array values as variables VS. Array values as "properti

Posted: Wed Jul 10, 2002 11:07 pm
by rd64pro
So, this should be an easy one for you guys, though it seems remarkably stupid to me...

Code: Select all

Example #1:

class Test {
    function get_month() {
        $todays_date = getdate();
        return 'This month is '. $todays_dateї'month'];
    }
}

$t = new Test;
print $t->get_month();

//output:
This month is July

Code: Select all

Example #2:

class Test {
    var $todays_date;
    function get_month() {
        $this->$todays_date = getdate();
        return 'This month is '. $this->$todays_dateї'month'];
    }
}

$t = new Test;
print $t->get_month();

//output:
This month is Array
You will note that the only difference is the use of $this, making $todays_date a "property" instead of a local variable.

Why does Example #2 not work correctly, and what approach do I need take to remedy this?

-Ryan

it's a property not a variable

Posted: Wed Jul 10, 2002 11:24 pm
by untouchable

Code: Select all

<?
class Test &#123;
    var $todays_date;
    function get_month() &#123;
        $this->todays_date = getdate();
        return 'This month is '. $this->todays_date&#1111;'month'];
    &#125;
&#125;

$t = new Test;
print $t->get_month();

$this->todays_date; //this is correct
$this->$todays_date; //this is not.
?>
I had trouble with this too...

Posted: Thu Jul 11, 2002 12:03 am
by rd64pro
Geeze... I feel like a dumb-ass. Thanks for help, untouchable.

-Ryan