How to fix Php 5.6 deprecated messages in Magento

I know, that Magento officially does not support Php 5.6, but as you may know, the latest version of Php (right now 5.6.1) comes with a lots of new features and optimizations, which could be handy. But those nasty deprecated messages “Deprecated functionality: iconv_set_encoding(): Use of iconv.internal_encoding is deprecated” fills Magento’s logs, right?
There is a temporary solution for this, simply we just have to override some core files of Magento (well, they are core Zend Framework files). Here are the steps to follow:
1. Create the following folders:
/app/code/local/Zend/Locale
/app/code/local/Zend/Service
/app/code/local/Zend/Validate
/app/code/local/Zend/XmlRpc

2. Copy the following files from /lib/Zend/ to /app/code/local/Zend/:
Locale/Format.php
Service/Audioscrobbler.php
Service/Technorati.php
Validate/Hostname.php
Validate/StringLength.php
XmlRpc/Client.php

3. Open the files from /app/code/local/Zend/ in a text editor and search for “internal_encoding” and replace them with “default_charset”. Before doing this, make sure that the “internal_encoding” string is a parameter of an iconv related function. Don’t replace “mb_internal_encoding”, “$internal_encoding” or any other non iconv related stuff, because it will break the code.

This solution is for Magento 1.8, but it should be very similar for 1.9 as well. If you are not sure, just search in all files for “internal_encoding” and do the three steps above for the needed files.

That’s all. Easy, isn’t it?

8 thoughts on “How to fix Php 5.6 deprecated messages in Magento”

  1. Hi there, First of all thanks for the information.Actually it solved my problem but partially. In my case the overriding of the file didn’t worked. I have to change to the core lib files to make it work. Do you have any suggestion on that?

    1. Very strange. Usually if you put in app/code/local the files exactly in the folder structure as they are originally (ex. Mage/something, Zend/somethingelse or Varien/third thing), then it will override the original classes. Of course you have to be careful to follow the naming of those files, to match exactly the original one (so uppercase-lowercase matters!). If it still doesn’t work, then I’d check the error logs and also look after the caching. Maybe there is a Magento compiler turned on, in that case you should rerun the compiler.

  2. Hi, just fyi: starting from v. 1.9.1.0 (released Nov 24, 2014) Magento support out-of-the-box PHP 5.6, because is shipped with ZF v. 1.12.7 that manage directly the switch between internal_encoding and default_charset for different PHP versions.

    1. Thanks Elias, This works perfectly on 1.7.02, 1.8.1 and 1.8.0. I don’t have a v1.9 to test with.

      Perhaps worth mentioning for any noobs, remember that you need to have the X permission on directories – e.g. 550 on directories (read and execute) and 440 on files (read only). The execute permission on a directory allows the program to CD into it. Without this, the patch will not be found.

      Note these are security settings. If your web server is not the owner you can set 750 and 740 respectively to make files editable.

      Thanks again Elias, great job!

      Mike

  3. You may want to use something like this if you have different PHP versions locally vs. on the production

    if (PHP_VERSION_ID < 50600) {
    iconv_set_encoding('input_encoding', 'UTF-8');
    iconv_set_encoding('output_encoding', 'UTF-8');
    iconv_set_encoding('internal_encoding', 'UTF-8');
    } else {
    ini_set('input_encoding', 'UTF-8');
    ini_set('output_encoding', 'UTF-8');
    ini_set('default_charset', 'UTF-8');
    }

Leave a Reply

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

Time limit is exhausted. Please reload the CAPTCHA.