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 =>


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


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:

public function __toString()
$tpl = $this->__config['template'];
$output = $this->fetch($tpl);
if ($this->isError($output))
$text = $this->__config['error_text'];
return $this->escape($text);
return $output;

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

public function display($tpl = null)
if (is_null($tpl) && $this->__config['template'] == "")
$this->__config['template'] = $tpl;
echo $this->__toString();

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

If You Appreciate What I Do Here On Seven PHP :: 7PHP, You Could Consider:

  1. Following me on Twitter | @7php
  2. LIKE-ing my FaceBook page
  3. Subscribe to my Email List - see top-right subscription box
  4. Help diffuse this interview to the PHP ecosystem - Share & Spread the word as far as you can ==> That would be a FREE way to thank me
  5. Use my DigitalOcean referral link if you plan to use it as your VPS (it starts at only $5/month btw) or if you can refer it to your friends, highly appreciated.
  6. Support via Paypal donate - my Paypal ID is

{I'm thankful to your response(s)!}

Valuable Feedback / Comment / Review From People Like You

  1. Brett Bieber says:

    The latest version is available from the download page, and also through the PEAR channel pear channel-discover && pear install

  2. Hi Brett, I’ve checked it, the changes are there. Thanks for the update.

  3. Mark Richards says:

    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.

  4. Is this even announced in the changelog?

    I searched for “__toString” but couldn’t find this.

  5. @Mark:
    You are welcomed :)

    I’ve searched the changelog, yes it seems like they did not even announced it..
    And the only information about it on the is:
    which also does not state that unfortunately..

    If you (or anyone) finds more about it, let us know.

    //K. Wasseem

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

  7. Igor, you are joking right? Your suggestion is wrong, the code is testing if $tpl is null, then set the config.


  1. Tweets that mention PHP + Savant3 + Solution To ‘Fatal error: Method Savant3::__tostring() cannot take arguments’ « 7PHP dot COM -- says:

    […] This post was mentioned on Twitter by K_Wasseem, K_Wasseem. K_Wasseem said: PHP + Savant3 + Solution To ‘Fatal error: Method Savant3::__tostring() cannot take arguments’ – [] […]

Speak Your Mind