Page 1 of 1

Error executing class declaration

Posted: Fri Apr 25, 2003 9:21 am
by tim wehr
I get an error (Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in .../groupparser.php on line 13 ) when executing a php document that has the class declaration shown below.

(It does not seem to like the var $insidegroup = false;
In fact, I have not gotten it to like ANYTHING other than a blank line, a comment, or a '}')

What am I missing?

My code (php version 4.2.3):

Code: Select all

<html>
<head>
<title>Group info parser</title>
</head>
<body>
<h2>Parsing group.xml</h2>

<?php 

	class GROUPParser &#123; 

// following items are unique to the group.
   var $insidegroup = false; 
   var $tag = ""; 
   var $groupID = "999999"; 						// will be used as reference by subscriber
																				// default value - overwritten if optional
																				// groupID tag is included in the xml
   var $grName = ""; 
   var $grStart = ""; 
   var $grExpire = ""; 
   var $grMax = ""; 

// following items will be unique to subscribers
   var $suLastName = ""; 
   var $suFirstName = ""; 

// following items are necessary for housekeeping
	 var $subscriberCount = 0;

   function startElement($parser, $tagName, $attrs) &#123; 
       if ($this->insidegroup) &#123; 
           $this->tag = strtoupper($tagName); 
       &#125; elseif (strtoupper($tagName) == "GROUP" || strtoupper($tagName) == "subscriber") &#123; 
           $this->insidegroup = true; 
       &#125; 
   &#125; 

   function endElement($parser, $tagName) &#123; 
       if (strtoupper($tagName) == "GROUP") &#123;
					 if ($groupID != "999999")  
					 		printf("There is already a groupID, so we will just add subscribers to this group."); 
           else
							printf("Here is where we add the group to the database and get the groupID."); 
           		printf("Here is where we add the final SQL to adjust groupID's for subscribers."); 
					 &#125;
					 
					// now we reinitialize everything to be ready for other groups in same xml document
           $this->tag = ""; 
           $this->groupID = "999999"; 
           $this->grName = ""; 
           $this->grStart = ""; 
           $this->grExpire = ""; 
           $this->grMax = ""; 
           $this->insideitem = false; 
       &#125; elseif (strtoupper($tagName) == "SUBSCRIBER") &#123;
					 if ($this->subscriberCount == $this->grMax) &#123;
					 		printf("Warning -- Too many subscribers for this group - subscriber skipped!");
					 &#125; else &#123;
					 		printf("Here is a line of SQL to insert one subscriber.");
					 		$this->subscriberCount += 1;
					 &#125;
           $this->suLastName = ""; 
           $this->suFirstName = ""; 
			 &#125;
   &#125; 

   function characterData($parser, $data) &#123; 
       if ($this->insidegroup) &#123; 
           switch ($this->tag) &#123; 
               case "GROUPID": 
               		$this->groupID .= $data; 
              		break; 
               case "GRNAME": 
               		$this->grName .= $data; 
               		break; 
               case "GRSTART": 
               		$this->grStart .= $data; 
               		break; 
               case "GREXPIRE": 
               		$this->grExpire .= $data; 
               		break; 
               case "GRMAX": 
               		$this->grMax .= $data; 
               		break; 
               case "SULASTNAME": 
               		$this->suLastName .= $data; 
               		break; 
               case "SUFIRSTNAME": 
               		$this->suFirstName .= $data; 
               		break; 
           &#125; 
       &#125; 
   &#125; 
&#125;

Posted: Fri Apr 25, 2003 9:33 am
by twigletmac
Have a read of the info on this page:
http://www.php.net/manual/en/language.oop.php

Have you tried using a constructer function?

Mac