I’m trying to call a function from within a heredoc, and I read in the manual (example #2) that it is possible. However, I get the following error: Notice: Undefined property: TIME::$since on line 13.
1 <?php class TIME {
2 var $month;
3 var $year;
4 public function since($y) {
5 $this->$month = (date("F"));
6 $this->$year = (date("Y")-$y);
7 return "(since $month of $year)";
8 // return "(since date('F') of {date('Y')-$y})";
9 }
10 }
11 $time = new TIME;
12 echo <<<EOF
13 {$time->since{1}};
14 EOF; ?>
What I need to do is pass 1 as an integer to the function since() and return a string like (since January of 2011).
You have a lot of errors in your code.
$this->$monthand$this->$yearmust be$this->monthand$this->yearin your case,return "(since $month of $year)";, I think, must bereturn "(since {$this->month} of {$this->year})";,{$time->since{1}};may be{$time->since(1)};, and, finally,EOF; ?>– ending PHP tag must be on newline when closing heredoc:P.S. Why are you using old, PHP4-style properties declaration?