PHP 5.3 __toString breaks Savant3 __toString with params

Just this week after upgrading my PHP version, I started getting this error when trying to use Savant 3: Fatal error: Method Savant3::__tostring() cannot take arguments in Savant3.php on line 192

PHP 5.3 no longer accepts parameters to it's magic function __toString() which conflicted with Savant's implementation which takes one parameter: $tpl.

  1. public function __toString($tpl = null)
  2. 	{
  3. 		$output = $this->fetch($tpl);
  4. 		if ($this->isError($output)) {
  5. 			$text = $this->__config['error_text'];
  6. 			return $this->escape($text);
  7. 		} else {
  8. 			return $output;
  9. 		}
  10. 	}

The fix involves changing this method so it doesn't take an argument and conforms with PHP 5.3. After a quick look at the code I realized the following changes were needed.

  1. Change the display method to
    1. 	public function display($tpl = null)
    2. 	{
    3.               if(!is_null($tpl))
    4.                  $this->config['template'] = $tpl;
    5. 		echo $this->__toString();
    6. 	}
  2. Then change the __toString method to use the config['template'] setting:
    1. 	public function __toString()
    2. 	{
    3.                 $tpl = $this->config['template'];
    4. 		$output = $this->fetch($tpl);
    5. 		if ($this->isError($output)) {
    6. 			$text = $this->__config['error_text'];
    7. 			return $this->escape($text);
    8. 		} else {
    9. 			return $output;
    10. 		}
    11. 	}