Array values as variables VS. Array values as "properti
Posted: Wed Jul 10, 2002 11:07 pm
So, this should be an easy one for you guys, though it seems remarkably stupid to me...
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
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 JulyCode: 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 ArrayWhy does Example #2 not work correctly, and what approach do I need take to remedy this?
-Ryan