PHP5 Problem debugging a class

Discussion in 'PHP' started by JA12, May 13, 2009.

  1. #1
    I've read everything I can find about passing arrays to functions and returning them, so I think I've got this right, but I still getting an error.

    Parse error: parse error, expecting `'('' in C:\xampp\htdocs\timebank\scripts\class.replace.php on line #

    The calling routine:
    
    include ("class.replace.php");
    $stR = new clsStringReplace;
    
    $row = mysql_query($result);
    $cmp = $stR->ReplaceAll($row);
    if (!$cmp) {
      echo $stR->getTheError;
      exit();
    }
    
    Code (markup):
    The Class:
    
    <?php
    class clsStringReplace
    {
      protected $SearchFor;
      protected $ReplaceWith;
      protected $Key;
      protected $Value;
      protected $myArray;
      protected $errorMsg;
    
    	/* 
        the constructor initializes the string replacement properties
    	*/
    	function __construct() {
        $this->SearchFor = '';
    		$this->ReplaceWith = '';
    		$this->Value = '';
    		$this->Key = '';
    		$this->errorMsg = '';
    	}
    	
    	function __toString() {
    		return "String Replace Class";
    	}
    
      /* replace a specific tag */
      public function ReplaceOne($pSearch, $pReplace, $pValue) {
        try {
          if (preg_match("/$pSearch/i", $pValue)) {
            $SearchFor = array ("/$pSearch/i");
            $ReplaceWith = array ($pReplace);
            $Value = preg_replace($SearchFor, $ReplaceWith, $pValue);
          }
          return $Value;
    [color=red]    } catch {   // <---- this the line the error refers to[/color]
          $errorMsg = 'ReplaceOne: failed - $SearchFor:' . $SearchFor . '; $ReplaceWith:' . $ReplaceWith . '; $value:' . $pValue;
          return false;
        }
      } 
    
      /* pass in a record set, replace all the tags in the values that might contain a tag */
      public function ReplaceAll($row) {
    
      }
    }
    
    Code (markup):
    I'm stumped. :confused: I've checked all the () and the {} and they are all paired, so I don't know what it's complaining about.
     
    JA12, May 13, 2009 IP
  2. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you're not catching the exception properly. you need to catch(someException as $error) { put $error text here}, not just catch{}!
     
    szalinski, May 13, 2009 IP
  3. Gordaen

    Gordaen Peon

    Messages:
    277
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Gordaen, May 13, 2009 IP