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. Quote 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] Quote 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. :) Quote Link to comment https://forums.phpfreaks.com/topic/20894-simple-oop-question/#findComment-92567 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.