Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bugfix for Zend Framework 1 in Magento (>= 1.7.*.*) + PHP 5.6
From 473846959772d8160b34b92ae3bcecddf24b972f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Julian=20Nu=C3=9F?= <julian.nuss@outlook.com>
Date: Tue, 23 Sep 2014 21:07:29 +0200
Subject: [PATCH 1/1] [BUGIFX] Zend Framework 1 + PHP5.6
---
lib/Zend/Locale/Format.php | 22 +++++++++++-----------
lib/Zend/Service/Audioscrobbler.php | 6 +++---
lib/Zend/Service/Technorati.php | 6 +++---
lib/Zend/Validate/Hostname.php | 4 ++--
lib/Zend/Validate/StringLength.php | 4 ++--
lib/Zend/XmlRpc/Client.php | 6 +++---
6 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/lib/Zend/Locale/Format.php b/lib/Zend/Locale/Format.php
index f1189f2..6280029 100644
--- a/lib/Zend/Locale/Format.php
+++ b/lib/Zend/Locale/Format.php
@@ -310,7 +310,7 @@ class Zend_Locale_Format
// Get correct signs for this locale
$symbols = Zend_Locale_Data::getList($options['locale'], 'symbols');
$oenc = iconv_get_encoding('internal_encoding');
- iconv_set_encoding('internal_encoding', 'UTF-8');
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('internal_encoding', 'UTF-8') : ini_set('default_charset', 'UTF-8');
// Get format
$format = $options['number_format'];
@@ -345,7 +345,7 @@ class Zend_Locale_Format
}
if (iconv_strpos($format, '0') === false) {
- iconv_set_encoding('internal_encoding', $oenc);
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('internal_encoding', $oenc) : ini_set('default_charset', 'UTF-8');
#require_once 'Zend/Locale/Exception.php';
throw new Zend_Locale_Exception('Wrong format... missing 0');
}
@@ -471,7 +471,7 @@ class Zend_Locale_Format
}
}
- iconv_set_encoding('internal_encoding', $oenc);
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('internal_encoding', $oenc) : ini_set('default_charset', 'UTF-8');
return (string) $format;
}
@@ -781,7 +781,7 @@ class Zend_Locale_Format
$result['locale'] = $options['locale']; // save the locale used to normalize $number (convenience)
$oenc = iconv_get_encoding('internal_encoding');
- iconv_set_encoding('internal_encoding', 'UTF-8');
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('internal_encoding', 'UTF-8') : ini_set('default_charset', 'UTF-8');
$day = iconv_strpos($format, 'd');
$month = iconv_strpos($format, 'M');
$year = iconv_strpos($format, 'y');
@@ -846,7 +846,7 @@ class Zend_Locale_Format
}
if (empty($parse)) {
- iconv_set_encoding('internal_encoding', $oenc);
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('internal_encoding', $oenc) : ini_set('default_charset', 'UTF-8');
#require_once 'Zend/Locale/Exception.php';
throw new Zend_Locale_Exception("Unknown date format, neither date nor time in '" . $format . "' found");
}
@@ -866,7 +866,7 @@ class Zend_Locale_Format
preg_match_all('/\d+/u', $number, $splitted);
if (count($splitted[0]) == 0) {
- iconv_set_encoding('internal_encoding', $oenc);
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('internal_encoding', $oenc) : ini_set('default_charset', 'UTF-8');
#require_once 'Zend/Locale/Exception.php';
throw new Zend_Locale_Exception("No date part in '$date' found.");
}
@@ -972,7 +972,7 @@ class Zend_Locale_Format
if (($position !== false) and ((iconv_strpos($date, $result['day']) === false) or
(isset($result['year']) and (iconv_strpos($date, $result['year']) === false)))) {
if ($options['fix_date'] !== true) {
- iconv_set_encoding('internal_encoding', $oenc);
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('internal_encoding', $oenc) : ini_set('default_charset', 'UTF-8');
#require_once 'Zend/Locale/Exception.php';
throw new Zend_Locale_Exception("Unable to parse date '$date' using '" . $format
. "' (false month, $position, $month)");
@@ -988,7 +988,7 @@ class Zend_Locale_Format
if (isset($result['day']) and isset($result['year'])) {
if ($result['day'] > 31) {
if ($options['fix_date'] !== true) {
- iconv_set_encoding('internal_encoding', $oenc);
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('internal_encoding', $oenc) : ini_set('default_charset', 'UTF-8');
#require_once 'Zend/Locale/Exception.php';
throw new Zend_Locale_Exception("Unable to parse date '$date' using '"
. $format . "' (d <> y)");
@@ -1004,7 +1004,7 @@ class Zend_Locale_Format
if (isset($result['month']) and isset($result['year'])) {
if ($result['month'] > 31) {
if ($options['fix_date'] !== true) {
- iconv_set_encoding('internal_encoding', $oenc);
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('internal_encoding', $oenc) : ini_set('default_charset', 'UTF-8');
#require_once 'Zend/Locale/Exception.php';
throw new Zend_Locale_Exception("Unable to parse date '$date' using '"
. $format . "' (M <> y)");
@@ -1020,7 +1020,7 @@ class Zend_Locale_Format
if (isset($result['month']) and isset($result['day'])) {
if ($result['month'] > 12) {
if ($options['fix_date'] !== true || $result['month'] > 31) {
- iconv_set_encoding('internal_encoding', $oenc);
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('internal_encoding', $oenc) : ini_set('default_charset', 'UTF-8');
#require_once 'Zend/Locale/Exception.php';
throw new Zend_Locale_Exception("Unable to parse date '$date' using '"
. $format . "' (M <> d)");
@@ -1047,7 +1047,7 @@ class Zend_Locale_Format
}
}
- iconv_set_encoding('internal_encoding', $oenc);
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('internal_encoding', $oenc) : ini_set('default_charset', 'UTF-8');
return $result;
}
diff --git a/lib/Zend/Service/Audioscrobbler.php b/lib/Zend/Service/Audioscrobbler.php
index c927fbe..1b32baf 100644
--- a/lib/Zend/Service/Audioscrobbler.php
+++ b/lib/Zend/Service/Audioscrobbler.php
@@ -69,9 +69,9 @@ class Zend_Service_Audioscrobbler
{
$this->set('version', '1.0');
- iconv_set_encoding('output_encoding', 'UTF-8');
- iconv_set_encoding('input_encoding', 'UTF-8');
- iconv_set_encoding('internal_encoding', 'UTF-8');
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('output_encoding', 'UTF-8') : ini_set('default_charset', 'UTF-8');
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('input_encoding', 'UTF-8') : ini_set('default_charset', 'UTF-8');
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('internal_encoding', 'UTF-8') : ini_set('default_charset', 'UTF-8');
}
/**
diff --git a/lib/Zend/Service/Technorati.php b/lib/Zend/Service/Technorati.php
index 647344b..0ad6b59 100644
--- a/lib/Zend/Service/Technorati.php
+++ b/lib/Zend/Service/Technorati.php
@@ -84,9 +84,9 @@ class Zend_Service_Technorati
*/
public function __construct($apiKey)
{
- iconv_set_encoding('output_encoding', 'UTF-8');
- iconv_set_encoding('input_encoding', 'UTF-8');
- iconv_set_encoding('internal_encoding', 'UTF-8');
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('output_encoding', 'UTF-8') : ini_set('default_charset', 'UTF-8');
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('input_encoding', 'UTF-8') : ini_set('default_charset', 'UTF-8');
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('internal_encoding', 'UTF-8') : ini_set('default_charset', 'UTF-8');
$this->_apiKey = $apiKey;
}
diff --git a/lib/Zend/Validate/Hostname.php b/lib/Zend/Validate/Hostname.php
index 2a27243..f1f04f0 100644
--- a/lib/Zend/Validate/Hostname.php
+++ b/lib/Zend/Validate/Hostname.php
@@ -550,7 +550,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
$status = false;
$origenc = iconv_get_encoding('internal_encoding');
- iconv_set_encoding('internal_encoding', 'UTF-8');
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('internal_encoding', 'UTF-8') : ini_set('default_charset', 'UTF-8');
do {
// First check TLD
$matches = array();
@@ -646,7 +646,7 @@ class Zend_Validate_Hostname extends Zend_Validate_Abstract
}
} while (false);
- iconv_set_encoding('internal_encoding', $origenc);
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('internal_encoding', $origenc) : ini_set('default_charset', 'UTF-8');
// If the input passes as an Internet domain name, and domain names are allowed, then the hostname
// passes validation
if ($status && ($this->_options['allow'] & self::ALLOW_DNS)) {
diff --git a/lib/Zend/Validate/StringLength.php b/lib/Zend/Validate/StringLength.php
index 2b7abe2..feb27f4 100644
--- a/lib/Zend/Validate/StringLength.php
+++ b/lib/Zend/Validate/StringLength.php
@@ -200,13 +200,13 @@ class Zend_Validate_StringLength extends Zend_Validate_Abstract
{
if ($encoding !== null) {
$orig = iconv_get_encoding('internal_encoding');
- $result = iconv_set_encoding('internal_encoding', $encoding);
+ $result = (PHP_VERSION_ID < 50600) ? iconv_set_encoding('internal_encoding', $encoding) : ini_set('default_charset', 'UTF-8');
if (!$result) {
#require_once 'Zend/Validate/Exception.php';
throw new Zend_Validate_Exception('Given encoding not supported on this OS!');
}
- iconv_set_encoding('internal_encoding', $orig);
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('internal_encoding', $orig) : ini_set('default_charset', 'UTF-8');
}
$this->_encoding = $encoding;
diff --git a/lib/Zend/XmlRpc/Client.php b/lib/Zend/XmlRpc/Client.php
index d3fb1da..3a262bf 100644
--- a/lib/Zend/XmlRpc/Client.php
+++ b/lib/Zend/XmlRpc/Client.php
@@ -257,9 +257,9 @@ class Zend_XmlRpc_Client
{
$this->_lastRequest = $request;
- iconv_set_encoding('input_encoding', 'UTF-8');
- iconv_set_encoding('output_encoding', 'UTF-8');
- iconv_set_encoding('internal_encoding', 'UTF-8');
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('input_encoding', 'UTF-8') : ini_set('default_charset', 'UTF-8');
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('output_encoding', 'UTF-8') : ini_set('default_charset', 'UTF-8');
+ (PHP_VERSION_ID < 50600) ? iconv_set_encoding('internal_encoding', 'UTF-8') : ini_set('default_charset', 'UTF-8');
$http = $this->getHttpClient();
if($http->getUri() === null) {
--
2.1.0
@amenk

This comment has been minimized.

Copy link

commented Sep 9, 2015

Thank you. Works like a charm.

@erikhansen

This comment has been minimized.

Copy link

commented Oct 28, 2015

This worked great on a Magento EE 1.13.1 install. Thanks.

@opensourcelib

This comment has been minimized.

Copy link

commented Nov 23, 2015

Thank you

@tadejoremuz

This comment has been minimized.

Copy link

commented Dec 28, 2015

Hi,
how can i apply this patch in Magento? Is it possible to run it or you must manually edit code in theese files?

@mautz-et-tong

This comment has been minimized.

Copy link

commented Jan 26, 2016

patch -p1 < 0001-BUGIFX-Magento-Zend-Framework-1-PHP5.6.patch will do the trick

@EliasKotlyar

This comment has been minimized.

Copy link

commented Jan 26, 2016

You may consider using a Core-Override Extension which i made: https://github.com/EliasKotlyar/MagentoPHP56

@tkn98

This comment has been minimized.

Copy link

commented Feb 1, 2016

@EliasKtlyar: No thanks, patch-file is very fine. Works.

@PedroKTFC

This comment has been minimized.

Copy link

commented Feb 10, 2016

I actually like the override extension approach as it keeps these changes separate to the core code. However, how do we manage to spot any future patches that might affect these files and so track them?

@vrkansagara

This comment has been minimized.

Copy link

commented Apr 12, 2016

no need to apply the patch just install php gd library and good to go. 👍

@jruzafa

This comment has been minimized.

Copy link

commented Jun 14, 2016

Work perfect, thanks !!!!

@Zifius

This comment has been minimized.

Copy link

commented Jun 15, 2016

@renttek can you please remove the extra ";"?

@pankaj-pareek

This comment has been minimized.

Copy link

commented Aug 2, 2016

Thanks, worked Perfect.

@bvdzung

This comment has been minimized.

Copy link

commented Nov 8, 2016

Wow. Thank pro. Very good.

Every body can down and "git app 0001-BUGIFX-Magento-Zend-Framework-1-PHP5.6.patch" => done

@EmileChiou

This comment has been minimized.

Copy link

commented Jan 25, 2017

Thanks you very much.

@renttek

This comment has been minimized.

Copy link
Owner Author

commented Jul 10, 2017

Oh, this gist still exists. totally forgot about it.

Update:
Removed the extra ";"

If anyone have to use tihs, I'd suggest to use the module mentioned by @EliasKotlyar : https://github.com/EliasKotlyar/MagentoPHP56
(Mentioned in: https://gist.github.com/renttek/29beaaa1e90909639501#gistcomment-1680671)

(If possible/suitable. If its not possible for you to use this module, feel free to apply this patch)

@blathrop

This comment has been minimized.

Copy link

commented Sep 28, 2017

Worked for me. Thanks!!

@renttek

This comment has been minimized.

Copy link
Owner Author

commented Sep 30, 2017

The latest version of M1 (1.9.3.6) seems to have this fix already. I'd say: upgrade to the latest version and don't use this

@sumithharshan

This comment has been minimized.

Copy link

commented Nov 15, 2017

Thank you. Perfectly worked with Magento ver. 1.9.0.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.