PHP + Savant3 + Solution To ‘Fatal error: Method Savant3::__tostring() cannot take arguments’ 

UPDATED Dec 2015: The maintainer of Savant (currently Brett Bieber has kinda abandoned the previous Savant project or he’s too not motivated to move it forward, and he is even very hostile to pull requests on github. So, I came up with a FORK of it and I’m happy to announce, I will be maintaining the new fork. So move from the old php savant to Savant PHP => http://7php.github.io/SavantPHP/

—–

If you are a PHP SAVANT user, and if you have switched to PHP 5.3, you will immediately notice that you get an error message when using it, something similar to: “Fatal error: Method Savant3::__tostring() cannot take arguments in /opt/lampp/htdocs/www/php/includes/lib/Savant3.php on line 192

I know you are eager for a solution, so let’s get to it and after that I will make some remarks and analysis.

Solution To Savant3 Error: Method Savant3::__tostring() cannot take arguments

Take It On Me Solution A

Updated Dec 2015: Please use the new improved Savant PHP – click

(it comes with namespace support and installable via composer – yay!)

=> Download my modified Savant3.php class file and overwrite yours

Do It YourSelf Solution B

Steps:

1) In your savant folder, find the php file named as “Savant3.php“.
2) Open Savant3.php
3) Go to line 182, or simple make a search for “public function __toString($tpl = null)
4) Replace the whole function body with the following:

[lang=’php’]
public function __toString()
{
$tpl = $this->__config[‘template’];
$output = $this->fetch($tpl);
if ($this->isError($output))
{
$text = $this->__config[‘error_text’];
return $this->escape($text);
}
else
return $output;
}
[/lang]

5) Go to line 950, or search for “public function display($tpl = null)
6) Replace the whole function body with the following:

[lang=’php’]
public function display($tpl = null)
{
if (is_null($tpl) && $this->__config[‘template’] == “”)
$this->__config[‘template’] = $tpl;
echo $this->__toString();
}
[/lang]

Why No Solution On the Savant3 Home Page

Currently, on the date of this post, the savant home page notifies its users of this potential issue. They claim to have fixed it and thus provided a modified version Savant 3.0.1. BUT this version does not seem to be available for download till now. I believe it might have been a confusion from either Paul or Brett, and they have somehow mixed the version Savant 3.0.0 with the Savant 3.0.1. Anyhow, I hope they fix it soon.

What’s Up With The __tostring() Issue?

Well, this issue is not with SAVANT as such, since it originates with the new PHP version 5.3
With PHP 5.3, the magic method __tostring() no more accepts any parameter.
As you might have guessed, SAVANT3 implements its __tostring() by accepting parameter $tpl which is now deprecated in favor of the new __tostring() for PHP 5.3

Khayrattee Wasseem's Picture

About Khayrattee Wasseem

PHP enthusiast | The PHP Community Fanboi | Founder of PHP Usergroup for Mauritius (#PhpMauritius) | Aspiring Entrepreneur | Ex-country Manager of a global award winning Magento Agency | Passionate about all things Wordpress & Servers

Mauritius https://wppp.io

8 comments

  1. I started using Savant a few weeks ago and had not suffered this error until I was working on a laptop with Xampp. Then the error appeared. I found your article. Downloaded the revised Savant… The problem remained. I applied your manual fixes to the latest Savant3.php and the problem was fixed. Uhhmm!!! Thanks for your help.

  2. In your code in step 6 is one bug, correct condition to be (!is_null($tpl) && $this->__config[‘template’] == “”)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.