Jump to content

[SOLVED] noob to OOP


HoTDaWg

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/52716-solved-noob-to-oop/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/52716-solved-noob-to-oop/#findComment-260279
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.