App works in php 5.3 but not 5.4+
Your code is failing as since PHP 5.4
, PHP has had its own hex2bin
function.
To resolve this you need to remove the hex2bin
function that you are using.
You might want to do a simple version check in an if
statement before the function is declared using phpversion()
:
if (!function_exists('hex2bin'))
{
function hex2bin($hex) {
if (strlen($hex) % 2)
$hex = "0".$hex;
$bin = '';
for ($i = 0; $i < strlen($hex); $i += 2) {
$bin .= chr(hexdec(substr($hex, $i, 2)));
}
return $bin;
}
}
From Github:
Since PHP 5.4 PHP provides its own hex2bin function, which causes the
hex2bin declaration in ykksm-util.php to fail, causing the error
below:PHP Fatal error: Cannot redeclare hex2bin()
Cheers to Ryan P for useful comment:
This code won't work - it calls
phpinfo()
with an invalid argument, and
callingphpversion("tidy")
will return the version of the tidy
extension (2.0). A better way is to just check for existence of the
function - i.e.if (!function_exists('hex2bin'))
{
Code not working when migrating from php v5.5 to php v5.3
Problem is in calling of that function. The following changes worked for me-
The following line modified -
$post_categories = sql_select_many("sql statement ", $connection)["rows"];
I removed ["rows"]
from end of the line.
New statements are-
$post_categories = sql_select_many("sql statement ", $connection);
$data = $post_categories["rows"];
Php square brackets syntax error
The first is because the new []
syntax for instantiating arrays only works in 5.4 and above. So, replace it with array()
:
// 5.4+ only:
array($userName => ['score' => $score]);
// 5.3 (and earlier) and 5.4+
array($userName => array('score' => $score));
The second is a different 5.4 feature, that of accessing arrays returned from functions, where you should use a temporary variable:
// 5.4+ only:
$this->Auth->user()['id']
// 5.3 (and earlier) and 5.4+:
$result = $this->Auth->user()
$result[id]
Or, for preference, upgrade your production server to a PHP version that's a bit more modern than the four-or-five year old version you're using. To save on more of these headaches, you either need to do that or start developing locally in 5.3. (If you need to do the latter, I'd look into virtualising your development setup, so you could develop in a virtual box against 5.3 for older production systems.)
Dreamweaver CS5 code hinting and syntax errors with PHP 5.4
The short answer is you can't extend code syntax for CS5. Adobe doesn't support older versions of Dreamweaver and there will not be a patch for it. They want you to upgrade to the latest (subscription-based) version instead.
Issues with running Code Igniter on a 5.3 php host
Yes, They are language constructs, Code igniter has no way to add them internally.
Your code needs to be 5.3 compatible if you wish to run in a 5.3 environment
Related Topics
Show Hide Payment Methods Based on Selected Shipping Method in Woocommerce
Optimizing Kohana-Based Websites for Speed and Scalability
Leverage Browser Caching, How on Apache or .Htaccess
How Would I Implement a Simple Site Search with PHP and MySQL
Explain $Ci =& Get_Instance();
Get Image Height and Width as Integer Values
How to Remove All Leading Zeroes in a String
Convert Datetime to String PHP
How to Get the Last 7 Characters of a PHP String
PHP Tree Structure for Categories and Sub Categories Without Looping a Query
How to Install Composer Globally on Windows
Accessing Files Relative to Bundle in Symfony2
Composer Install Error - Requires Ext_Curl When It's Actually Enabled