pedrobcabral Posted September 15, 2006 Share Posted September 15, 2006 The following does work:[code]$day = date('d');echo $day;[/code]The following does not work:[code]class day {var $day = date('d');function display() {echo $this->day;}}$speak = new day;$speak->display();[/code]Why the second does not work? The problem it's on var $day = date('d'); but i can't figure out what.Thank you. Link to comment https://forums.phpfreaks.com/topic/20894-simple-oop-question/ Share on other sites More sharing options...
Daniel0 Posted September 15, 2006 Share Posted September 15, 2006 Because the only variables you can define using [tt]var[/tt] is arrays. Others have to be defined in a function. Example: [code]<?phpclass day{ var $day; function day() { $this->day = date('d'); } function display() { echo $this->day; }}$speak = new day();$speak->display();?>[/code] Link to comment https://forums.phpfreaks.com/topic/20894-simple-oop-question/#findComment-92565 Share on other sites More sharing options...
pedrobcabral Posted September 15, 2006 Author Share Posted September 15, 2006 thank you very much. :) Link to comment https://forums.phpfreaks.com/topic/20894-simple-oop-question/#findComment-92567 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.