Hold Tight...

0 %
Driving cybersecurity excellence
Innovator behind Kodachi OS
  • Residence:
    ::0
  • Uptime Binary:
    110001
  • Mantra:
    Innovate, Secure, Repeat
ONS
EEDS
NSSG
Cybersecurity
Programming & R&D
Cryptocurrency
AI & vibe coding
  • Bash
  • Gambas
  • Delphi
  • PHP
  • Visual Basic
  • Rust

Migrating from PHP 5.6 to 7.3

01/11/2019
3 min readDeep Tech3 code examplesUpdated October 2026

Key points

  • Moving digi77.com from PHP 5.6 to 7.3 broke two things: a plugin using preg_replace with the removed /e modifier, and code using mcrypt.
  • The /e fix still holds in PHP 8: preg_replace_callback() is the replacement.
  • Upgrading today, go straight to PHP 8.4 or 8.5, and use OpenSSL or sodium instead of mcrypt.

Upgrading digi77.com: From PHP 5.6 to 7.3

Updated October 2026: My move from PHP 5.6 to 7.3 is history now: PHP 7.3 reached its end of life on 6 December 2021, and no PHP 7 release gets security fixes any more. If you are upgrading today, go straight to PHP 8.4 or 8.5; PHP 8.2 gets its last security fixes on 31 December 2026 (see php.net/supported-versions). Notes on the two fixes below:

  • The /e fix still holds in PHP 8: preg_replace_callback() is the right replacement. The wp-code-highlight plugin itself was last updated twelve years ago (tested up to WordPress 3.9), so replace it instead of patching it; the code on this page is now shown with the Code Block Pro block.
  • mcrypt was removed from PHP in 7.2, and the libmcrypt library behind it has not been maintained since 2007. The PECL mcrypt extension still exists (1.0.9, August 2025), but new code should use OpenSSL (openssl_encrypt()) or the sodium functions built into PHP since 7.2. Data encrypted with MCRYPT_RIJNDAEL_256 is not AES-256 (its block size is 256 bits), so plan to decrypt and re-encrypt it.
  • CentOS 7 reached its end of life on 30 June 2024, and the cPanel ea-php72 and ea-php73 packages are retired; current cPanel runs on AlmaLinux, Rocky Linux, CloudLinux or Ubuntu.

Why I upgraded digi77.com

I finally decided to upgrade digi77.com from PHP version 5.6 to 7.3 to benefit from the latest security enhancements and speed improvements. While I don’t regret making this upgrade, I encountered a few issues along the way. I would like to share these experiences with you to help you resolve similar problems more easily if you face them.

wp-code-highlight plugin

Once I updated to PHP 7.3, WordPress crashed due to one of the plugins, wp-code-highlight. This plugin uses preg_replace with the /e modifier to convert a double quote " into \". Unfortunately, the /e modifier was deprecated in PHP 5.5 and removed in PHP 7.0. To solve this, you need to use an anonymous function to pass the matches to your function. By updating the code to use an anonymous function, the issue with the wp-code-highlight plugin can be resolved, ensuring compatibility with PHP 7.3.

The file that had to be changed is wp-code-highlight.php.

The old function code was:
Please replace the word xre with pre. I had to change it because I was using the same plugin on this post when I wrote it!

PHP
function wp_code_highlight_filter($content) {

	if(get_option('wp_code_highlight_line_numbers')=='enable'){

		$line_numbers=' linenums:1';

	}

	else{

		$line_numbers='';

	}

	return preg_replace("/<xre(.*?)>(.*?)<\/xre>/ise",

		"'<xre class=\"prettyprint$line_numbers\">'.wch_stripslashes('$2').'</xre>'", $content);

}
PHP

The fix is to use preg_replace_callback. Here is how I implemented it:

First, you need to find the part of the code that uses preg_replace with the /e modifier. Then, replace it with preg_replace_callback, which allows you to pass an anonymous function to handle the matches.

Please replace the word xre with pre in your actual code. I had to change it because I was using the same plugin in this post when I wrote it!

PHP
function wp_code_highlight_filter($content) {
/*  Warith new code */
	return preg_replace_callback("/<xre(.*?)>(.*?)<\/xre>/is",function($m) { if(get_option('wp_code_highlight_line_numbers')=='enable'){ $line_numbers=' linenums:1'; } else{ 	$line_numbers=''; }; return '<xre class="prettyprint'.$line_numbers.'">'.wch_stripslashes($m[2]).'</xre>'; },$content);

}
PHP

That made WordPress work smoothly again with PHP 7.3.


mcrypt extension

The other issue I faced was that the Stealthwalker VPN software (now one of my archived projects) used mcrypt on the server side to decrypt login details, and this encryption extension was deprecated in PHP 7.1 and removed in PHP 7.2. To resolve this issue, I used the following commands on CentOS with cPanel:

ShellScript
# Install epel-release repo if you do not already have it installed
yum install epel-release
# Install libmcrypt and libmcrypt-devel rpms needed for the PHP extensions.
yum install libmcrypt libmcrypt-devel
# Update all Pecl php versions.
for version in $(ls /opt/cpanel|grep ea-php); do /opt/cpanel/${version}/root/usr/bin/pecl channel-update pecl.php.net; done
# Install Mcrypt PHP extensions via Pecl for PHP72 and PHP73
/opt/cpanel/ea-php72/root/usr/bin/pecl install channel://pecl.php.net/mcrypt-1.0.1
/opt/cpanel/ea-php73/root/usr/bin/pecl install channel://pecl.php.net/mcrypt-1.0.2
# Restart Apache/Litespeed to make the new PHP extensions active.
service httpd restart
# Basically you are done by now but to check for the mcrypt extensions showing. credits goes to whattheserver.com
for phpver in $(ls -1 /opt/cpanel/ |grep ea-php | sed 's/ea-php//g') ; do echo "PHP $phpver" ; /opt/cpanel/ea-php$phpver/root/usr/bin/php -m |grep -E 'mcrypt'; done
ShellScript

Posted in Deep Tech