Magento: Object __tostring() cannot take arguments

I came up against this issue in Magento earlier.

Method Varien_Object::__toString() cannot take arguments

There's quite a lot of documentation about this on the net, so really this post is more for my own reference should I hit up against it again!


Older versions of Magento require PHP 5.3.2, which is great unless of course it turns out that 5.3.2 has security vulnerabilities in it. So, the easy solution of not upgrading PHP can't be used (wouldn't recommend this even if there weren't vulns personally).

So what we've got to do instead is get down and dirty with the code. Actually there's two things to change, so it's not really the end of the world!

Open file lib/Varien/Object.php

On or around line 488 you should see

public function __toString(array $arrAttributes = array(), $valueSeperator=",")


We simply need to change the name of the function to __invoke, so

public function __invoke(array $arrAttributes = array(), $valueSeperator=",")


If you load the page now you'll probably get an error about too many redirects, so we need to replace use of split() with explode().

Open app/code/core/Mage/Core/Controller/Request/Http.php

On or around line 274 will be

$host = split(':',$_SERVER['HTTP_HOST']);

change this to

$host = explode(':',$_SERVER['HTTP_HOST']);


Now you should find your site is working. Honestly, it's pretty poor when your software relies on a specific minor release of PHP, but I guess if a major change is made between minor releases what are you going to do? The latest version fixes this though, so if upgrading Magento is an option for you, it's worthwhile.