Magento not working on PHP 5.3

For those who have noticed this error

Fatal error: Method Varien_Object::__tostring() cannot take arguments in /magento/lib/Varien/Object.php

when trying to install Magento on PHP 5.3, do not fear, here is the fix:

File: /lib/Varien/Object.php (Line 484)

Change from

public function ___toString(array $arrAttributes = array(), $valueSeparator=’,')

To this

public function __invoke(array $arrAttributes = array(), $valueSeparator=’,')

File /app/code/core/Mage/Core/Controller/Request/Http.php (Line 274)

Change from

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

To this

$host = explode(‘:’, $_SERVER['HTTP_HOST']);
Credits to naujasdizainas.lt on http://www.magentocommerce.com/boards/viewthread/18080/
Thanks Idress Haddad for pointing out the use of apostrophe instead of single quote in the codes. Updated! :)
Note: Please use single quotes instead of apostrophe!

51 Responses to Magento not working on PHP 5.3

  1. Kapil says:

    Thanks, it works perfectly for me.

  2. Thomas says:

    Thank you!
    You are the man!

  3. Giuseppe says:

    Thanks a lot! It works perfectly.

  4. Thanks!! works perfect!! cheers!!

  5. Shawn says:

    It works but later on when you try to add products and other tasks you get errors similar to
    “Function split() is deprecated in ………line xxx”
    At which time you need to change the split() to explode()
    Or is it just me getting these errors.

  6. Tanish says:

    Thanks a ton. Just Saved my day. I was about to install a lower version of WAMP..

  7. Pingback: PHP 5.3 and Magento | The nocturnart blog

  8. Dinesh says:

    Thanks Dear it’s realy worked

  9. Alex says:

    Thanks! It worked! :D

  10. Brandaspect says:

    Your a legend, After installing Snow Leopard, it all went wrong but now works fine following your fixes. well done

  11. Your solution is incomplete, after you change the __toString to __toInvoke, add this:

    function __toString() {
    return $this->__invoke( func_get_arg(0), func_get_arg(1) );
    }

  12. Rob says:

    Tried it then got this error : Parse error: parse error, expecting `’&” or `T_VARIABLE’ in C:\lib\Varien\Object.php on line 498

  13. Idrees Haddad says:

    Rob
    The two lines get you pass the installation error

    BUT

    Note that there are two typos in the correction lines (an apostrophe is used in the end of the lines instead of the single quote):

    The correct lines are:

    public function __invoke(array $arrAttributes = array(), $valueSeparator=’,')

    AND

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

  14. spikomoko says:

    Thanks Idrees Haddad, have noted the mistakes and corrected it. :)

  15. Idrees Haddad says:

    [UPDATE]

    I don’t know why BUT after posting the comment the single quote gets changed to apostrophe.

    Correct the first line: at the end before the comma , should be single quote.

    Correct the second line: before the colon should be a single quote too.

  16. spikomoko says:

    Ok, this looks like WordPress is causing this.

  17. Bunker says:

    Are you a professional journalist? You write very well.

  18. alvin says:

    There is another file that needs to be changed

    File /app/code/core/Mage/Admin/Model/User.php (Line 374)

    From:

    $nodePath = ‘adminhtml/menu/’ . join(‘/children/’, split(‘/’, $startupPage)) . ‘/action’;

    To

    $nodePath = ‘adminhtml/menu/’ . join(‘/children/’, explode(‘/’, $startupPage)) . ‘/action’;

  19. Pingback: De eerste install » CustomizeMagento.net Blog

  20. Floost says:

    I read a few topics. I respect your work and added blog to favorites.

  21. Ventego says:

    In truth, immediately i didn’t understand the essence. But after re-reading all at once became clear.

  22. angelsuga says:

    hi, thanks. Its perfectly works. then could you guide me how to install sample data on magento 1.2.0

    • spikomoko says:

      You have to copy the sample data files into the the magento folder, run the SQL script that comes with it then install magento. I believe there is good tutorial in the documentation section on Magento site.

  23. Maha says:

    thanks a million!

  24. Mackeran says:

    Very interesting and amusing subject. I read with great pleasure.

  25. Thank you worked a treat

  26. Robin says:

    Great, worked for me!

  27. Cristian says:

    Thanks man!!!! It’s great!!!! worked very well for me!

  28. 7Fingers says:

    Fine thanks ;-)

  29. Hi,
    Thanks you saved my day. I was new to Magento and such errors would have blown my mind.
    Thanks again

  30. ZoiaoDePeixe says:

    Thanks very much, this helps a lot, working now, hehehe.

  31. thanks!! great solution.

  32. CSSJockey says:

    Thanks for sharing this fix. Keep it up.

  33. katie says:

    I was about to downgrade but got your fix. You are a life saver.

    split() is deprecated so you need to change all instances of split to explode();

    Thanks a lot.

  34. Adam Cleaner says:

    not sure if it’s because i’m on windows 7, but no matter what i try i still end up with errors after sorting out the configuration part, which gives an error code (can’t remember just yet bu tihnk it was 8109) and then when i refresh another error messages, which wont go until i dlelete everything and start again for the hundreth time :(

  35. Pingback: GUYA.NET » Blog Archive » Pitfalls to avoid when installing Magento on XAMP

  36. Hey says:

    There is even an easier way to fix this – just change the Varien_Object::__toString() as follows:

    public function __toString()
    {
    if(func_num_args() > 0)
    {
    $arrAttributes = func_get_arg(0);
    }
    else
    {
    $arrAttributes = array();
    }

    if(func_num_args() > 1)
    {
    $valueSeparator = func_get_arg(1);
    }
    else
    {
    $valueSeparator = ‘,’;
    }

    $arrData = $this->toArray($arrAttributes);
    return implode($valueSeparator, $arrData);
    }

  37. Chris says:

    That worked perfectly.
    Very easy to follow instructions! Good work!

  38. Ravi says:

    Great!! It works perfectly for me. Thank you very much

  39. Sylvia says:

    works perfectly for me! Thank you so much!

  40. Brian says:

    Why haven’t the Magento folks fixed this yet? It’s June, 2010.

  41. Manav says:

    it’s not working for me i got an error
    Parse error: parse error, expecting `’&” or `T_VARIABLE’ in G:\wamp\www\pro\lib\Varien\Object.php on line 485

    • Hafsa says:

      hello did u find solution for this parse error, if yes please help me I couldn’t found it, thank u in advance

  42. vignesh says:

    another one place you have to convert replace split into explode

    app\code\core\Mage\CatalogIndex\Model\Aggregation.php

    Line no:154

    Function name: function _processTags

  43. vignesh says:

    This is perfectly working in Magento ver. 1.3.1

    I used that really.. But this two place missing to replace split into explode..

    app\code\core\Mage\CatalogIndex\Model\Aggregation.php
    Line no:154
    Function name: function _processTags()

    app\code\core\Mage\Admin\Model\User.php
    Line no:361
    Function name: getStartupPageUrl()

  44. Mark says:

    Perfect thank you for this – works perfectly.

  45. You have a great blog here, I really love the way you write
    very simple and to the point. Keep your good work coming.

  46. Thank you thank you thank you!!!

  47. Pingback: Running magento on PHP 5.3 « Blogicia

  48. The main implementation of PHP is now produced by The PHP Group and serves as the formal reference to the PHP language. PHP is free software released under the PHP License, which is incompatible with the GNU General Public License due to restrictions on the usage of the term PHP. Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.