HoTDaWg Posted May 23, 2007 Share Posted May 23, 2007 check it out: <?php //begin the script for date and time class datebones { //day var $dayfull = date('l'); //month var $monthfull = date('F'); var $monthnumber = date('m'); //date var $datenozero = date('j'); var $datewithzero = date('d'); //year var $yearfull = date('Y'); var $yearshort = date('y'); } $datebones = &new datebones; echo $datebones->dayfull; ?> it is giving me the followin error: or: syntax error, unexpected '(', expecting ',' or ';' in C:\xampp\htdocs\xampp\mystuff\eYaMod\dateandtime.php on line 5 any ideas? ??? thanks, HoTDaWg Quote Link to comment https://forums.phpfreaks.com/topic/52716-solved-noob-to-oop/ Share on other sites More sharing options...
per1os Posted May 23, 2007 Share Posted May 23, 2007 What version of PHP are you using, if you are using 4, that will not work. Something like this would though <?php //begin the script for date and time class datebones { //day var $dayfull = ''; //month var $monthfull = ''; var $monthnumber = ''; //date var $datenozero = ''; var $datewithzero = ''; //year var $yearfull = ''; var $yearshort = ''; function datebones() { $this->dayfull = date('l'); $this->monthfull = date('F'); $this->monthnumber = date('m'); $this->datenozero = date('j'); $this->datewithzero = date('d'); $this->yearfull = date('Y'); $this->yearshort = date('y'); } } $datebones = new datebones(); // why use the reference here? echo $datebones->dayfull; ?> Reason being PHP 4 does not pay attention to the definition of vars outside of function other than acknowleding that they are there. If you are using PHP5, wel I am sure it has something to do with the date function being there. Quote Link to comment https://forums.phpfreaks.com/topic/52716-solved-noob-to-oop/#findComment-260279 Share on other sites More sharing options...
448191 Posted May 23, 2007 Share Posted May 23, 2007 That no worky on php5 either. The thing is that when initializing properties only values are allowed, not expressions. Simple as that. Quote Link to comment https://forums.phpfreaks.com/topic/52716-solved-noob-to-oop/#findComment-260326 Share on other sites More sharing options...
HoTDaWg Posted May 23, 2007 Author Share Posted May 23, 2007 thanks guys:)! Quote Link to comment https://forums.phpfreaks.com/topic/52716-solved-noob-to-oop/#findComment-260332 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.