Page 1 of 1

T_VAR

Posted: Wed Jul 04, 2007 11:27 am
by nightman
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Dear all I would appreciate it greatly if anyone could help with this code.  My knowledge does not go beyond a few tutorials.  I get this error message:

"Parse error: syntax error, unexpected T_VAR, expecting '{' in c:\program files\apache group\Apache\htdocs\date_pulldown.class.php on line 3"


when I try to run when I run the code below.  My basic understanding tells me that when script [1] tries to communicate with script [2] it balks on line 3 - thanks in advance:

[1]

Code: Select all

<html>
<head>
<title>Listing 12.4 Using the date_pulldown Class</title>
</head>
<?php
include("date_pulldown.class.php");
$date1 = new date_pulldown("fromdate");
$date2 = new date_pulldown("todate");
$date3 = new date_pulldown("foundingdate");
$date3->setYearStart(1972);
if (empty($foundingdate))
$date3->setDate_array(array('mday'=>26, 'mon'=>4, 'year'=>1984));
?>
<body>

<form>
From:<br>
<?php print $date1->output(); ?><p>

To:<br>
<?php print $date2->output(); ?><p>
Company founded:<br>
<?php print $date3->output(); ?><p>
<input type="submit">
</form>
</body>
</html>


[2]

Code: Select all

<?PHP
 class date_pulldown
    var $name;                                //offending, line 3, tried switching 'var' to 'private' no fix
    var $timestamp = -1;
    var $months = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    var $yearstart = -1;
    var $yearend = -1;

 function date_pulldown($name) {
    $this->name = $name;
 }
    function setDate_global() {
      if (!$this->setDate_array($GLOBALS[$this->name])) {
          return $this->setDate_timestamp(time());
      }

      return true;
 }

      function setDate_timestamp($time) {
         $this->timestamp = $time;
         return true;
      }

      function setDate_array($inputdate) {
        if (is_array($inputdate) &&
            isset($inputdate['mon']) &&
            isset($inputdate['mday']) &&
            isset($inputdate['year'])) {

            $this->timestamp = mktime(11, 59, 59,
            $inputdate['mon'], $inputdate['mday'], $inputdate['year']);

            return true;
        }

        return false;
 }
 
 function setYearStart($year) {
   $this->yearstart = $year;
 }

 function setYearEnd($year) {
   $this->yearend = $year;
 }

 function getYearStart() {
   if ($this->yearstart < 0) {
      $nowarray = getdate(time());
      $this->yearstart = $nowarray[year]-5;
   }

   return $this->yearstart;
 }

 function getYearEnd() {
   if ($this->yearend < 0) {
      $nowarray = getdate(time());
      $this->yearend = $nowarray[year]+5;
   }
   return $this->yearend;
 }
 function output() {
   if ($this->timestamp < 0) {
       $this->setDate_global();
   }
   $datearray = getdate($this->timestamp);
   $out = $this->day_select($this->name, $datearray);
   $out .= $this->month_select($this->name, $datearray);
   $out .= $this->year_select($this->name, $datearray);
   return $out;
 }

 function day_select($fieldname, $datearray) {
   $out = "<select name=\"$fieldname"."[mday]\">\n";
   for ($x=1; $x<=31; $x++) {
      $out .= "<option value=\"$x\"".($datearray['mday']==($x)
        ?" SELECTED":"").">".sprintf("%02d", $x) ."\n";
   }
   $out .= "</select>\n";
   return $out;
 }

 function month_select($fieldname, $datearray) {
   $out = "<select name=\"$fieldname"."[mon]\">\n";
   for ($x = 1; $x <= 12; $x++) {
      $out .= "<option value=\"".($x)."\"".($datearray['mon']==($x)
        ?" SELECTED":"")."> ".$this->months[$x-1]."\n";
   }
   $out .= "</select>\n";
   return $out;
 }

 function year_select($fieldname, $datearray) {
   $out = "<select name=\"$fieldname"."[year]\">";
   $start = $this->getYearStart();
   $end = $this->getYearEnd();
   for ($x= $start; $x < $end; $x++) {
      $out .= "<option value=\"$x\"".($datearray['year']==($x)
         ?" SELECTED":"").">$x\n";
   }
   $out .= "</select>\n";
   return $out;
 }
}
?>
p.s. if there is tutorial or .pdf which covers all known T_VAR issues I would be much obliged. I have tested the script with PHP 5.0.2 and 5.1.2 both mimicked the same results. I have looked around a bit and all I have found are suggestions which indicate maybe a bracket is out of place or that 'private' should be declared instead of using 'var'. I tried switching to both 'var' and 'private' but no fix.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Jul 04, 2007 11:30 am
by volka
class date_pulldown
var $name; //offending, line 3, tried switching 'var' to 'private' no fix
should be

Code: Select all

class date_pulldown {
  var $name;

Posted: Wed Jul 04, 2007 11:34 am
by aceconcepts
Try placing a bracket { after

Code: Select all

class date_pulldown
And also a closing one where the class ends.

It Worked

Posted: Wed Jul 04, 2007 12:02 pm
by nightman
"Try placing a bracket { after class date_pulldown"

Thanks allot - the extra bracket fixed it, (I was thinking that myself but couldn't spot it). After inserting the missing bracket I copied and pasted the file into notepad2. Then I placed the cursor next to the newly inserted bracket which showed the newly inserted bracket was paired to the 2nd to last bracket on the second to last line of script [2].