Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fburn
    New Member
    • Jul 2008
    • 2

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE

    I need some help with an error I'm getting using php 5.2.5 running on linux.

    I receive an error:

    Parse error: syntax error, unexpected T_ENCAPSED_AND_ WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/html/inventoryContro l/supplier.php on line 26 (line number changed to match code tags)

    The code is as follows:

    Code:
           
    // get a supplier using the supplier id
    function getSupplier($supplierID = NULL) {
    
    	// initialize the supplier to the null
    	$supplier = NULL;
    		
    	// check for NULL arguments
    	if (!is_null($supplierID)) {
    			
    		// get the connection to the database
    		$con = db_connect();
    			
    		// sql select statement 
    		$sql = "SELECT * FROM suppliers WHERE supplier_id = '" . $supplierID . "'";
    			
    		// execute the query
    		$result = mysql_query($sql, $con);
    			
    		if ($record = mysql_fetch_assoc($result)) {
    				
    			// create empty supplier object
    			$supplier = new Supplier;
    				
    			// set attributes
    			$supplier->setSupplierID($supplierID);
    			$supplier->setFirstName($record['first_name']);
    			$supplier->setLastName($record['last_name']);
    			$supplier->setOrganization($record['organization']);
    			$supplier->setPhone($record['phone']);
    			$supplier->setFax($record['fax']);
    			$supplier->setMobile($record['mobile']);
    			$supplier->setEmail($record['email']);
    			$supplier->setAddress1($record['address1']);
    			$supplier->setAddress2($record['address2']);
    			$supplier->setCity($record['city']);
    			$supplier->setState($record['state']);
    			$supplier->setCountry($record['country']);
    			$supplier->setPostcode($record['postcode']);
    		} // if
    			
    		// close the database connection
    		db_close($con);
    	} // if
    		
    	// return found ? populated supplier : NULL
    	return $supplier;
    } // getSupplier()
    The bit that's dying is any/all of the $supplier->setBlah($recor d['...']);

    Strangely, I have code that is exactly the same in multiple software systems, including this one that are basically identical without the problem. Example of code without parse error:

    Code:
            
    // get an instance of a Customer using the customerID
    function getCustomer($customerID = NULL) {
    	 
     	// return value
    	$customer = NULL;
    		
     	// check for null arguments
    	if (!is_null($customerID)) {
    			
    		// get the database connection
    		$con = db_connect();
    		
    		// sql select statement
    		$sql = "SELECT * FROM customers WHERE customer_id = '" . $customerID . "'";
    			
    		// execute the query
    		$result = mysql_query($sql, $con);
    			
    		// check for a result 
    		if ($record = mysql_fetch_assoc($result)) {
    									
    			// create empty customer object
    			$customer = new Customer;
    				
    			// populate attributes
    			$customer->setCustomerID($customerID);
    			$customer->setFirstName($record['first_name']);
    			$customer->setLastName($record['last_name']);
    			$customer->setOrganization($record['organization']);
    			$customer->setPhone($record['phone']);
    			$customer->setFax($record['fax']);
    			$customer->setMobile($record['mobile']);
    			$customer->setEmail($record['email']);
    			$customer->setAddress1($record['address1']);
    			$customer->setAddress2($record['address2']);
    			$customer->setCity($record['city']);
    			$customer->setState($record['state']);
    			$customer->setCountry($record['country']);
    			$customer->setPostcode($record['postcode']);
    			$customer->setTier($record['tier']);
    		} // if
    		
    		// close the database connection
    		db_close($con);
    	} // if
    	
    	// return found ? populated customer : NULL
    	return $customer;
    } // getCustomer()

    Anyway, I'm stumped! Help me please!

    Finnian Burn
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Finnian.

    I see this sometimes when I mistype a single quote when I need a double quote or vice versa.

    Also make sure you don't have an errant quote or backtick (`) somewhere where it doesn't belong.

    Comment

    • fburn
      New Member
      • Jul 2008
      • 2

      #3
      Originally posted by pbmods
      Heya, Finnian.

      I see this sometimes when I mistype a single quote when I need a double quote or vice versa.

      Also make sure you don't have an errant quote or backtick (`) somewhere where it doesn't belong.
      I've only used single quotes for associative array access and no backticks anywhere. Any other ideas?

      I've also cut-and-pasted the code that works ($customer->setBlah[...]) to the supplier method/object and simply renamed the object reference from $customer to $supplier in each instance it is used and still continue to get the error.

      Could it be an actual bug in the parsing engine for PHP?

      Finnian

      Comment

      Working...