I am trying to create a
Calendar class
that takes a new DateTime
in its constructor or left blank to use the current time.
<?php
class Calendar
{
public $dateTime = null;
public function __construct($dateTime = new DateTime())
{
$this->dateTime = $dateTime;
echo $this->dateTime->format('m-d-Y') . "\n";
}
}
date_default_timezone_set('UTC');
$cal = new Calendar();
?>
but I keep getting this:
Parse error: parse error in /Users/nfior2/www/projects/companies/cortlandt/activities/cal.php on line 5
If I change line 5
public function __construct($dateTime = new DateTime())
to use int
public function __construct($dateTime=10)
and adjust the function __construct()
body a bit without using DateTime::format
... it works as I would expect.
Can anyone tell me what is going on here or how I can get to the bottom of this?