Make PEAR IT-templates work on a PHP 7 server

Some of my older PHP programs use PEAR-IT-templates. At the core of this PHP template engine is the "IT.php" file defining a class "HTML_Template_IT" via an old fashioned "contructor" function of the same name (stemming from old PHP4's way to define classes).

Yesterday, I needed to make some IT-templates work on an Apache2 server with PHP 7.1. This was easier than expected: Setting PHP to display all warnings and errors leads directly to the right code statements which must be corrected:

Correcting the call of preg_replace

In a first step we can ignore the warning about the old fashioned class declaration, which will sooner or later disappear from PHP. What absolutely needs to be changed, however, is an error that arises due to a special usage of the function preg_replace():

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback

In my PEAR IT-installation the problem is located around line 956 of the file "IT.php". Fortunately, some other clever people have already provided a method, how to replace the critical statement:

        // Replace the following lines by the subsequent statements
        /*
        return preg_replace(
            "#<!-- INCLUDE (.*) -->#ime", "\$this->getFile('\\1')", $content
        );
        */
	return preg_replace_callback(
	   "#<!-- INCLUDE (.*) -->#im",
	    array($this, 'getFile'),
	    $content
	);

See the contribution of A. Preuss in the following stack overflow post:
http://stackoverflow.com/questions/22597102/preg-replace-the-e-modifier-is-deprecated-error

Worked perfectly for me. Many thanks to A. Preuss!

Changing to a __construct() function

To get rid of the warning regarding the old fashioned class constructor function just replace the function definition around line 376 by

    // function HTML_Template_IT($root = "", $options=null) {
    function __construct($root = "", $options=null) {

With both the replacements described above I could use my old IT-template dependent PHP programs successfully on a PHP 7.1 system! This, hopefully, gives me enough time to replace the PEAR IT engine by the Smarty engine wherever reasonable :-).

PhpMyAdmin 4.7 on Opensuse Leap 42.2 – install PHP 7 and correct some code to avoid errors

Yesterday, I wanted to change to the latest version of PhpMyAdmin (4.7) on my development laptop which runs on Opensuse Leap 42.2. PHP 5.6 was provided via an Apache2 server and php-apache-modules. I downloaded the zipped code package for PhpMyAdmin and performed the usual setup procedure on my local web server. But I met some obstacles both under and after the phpmyadmin installation.

First, I got an error during installation of the following type:

phpmyadmin fatal error: call to undefined function phpseclib\crypt\random::string() in .../phpmyadmin/libraries/config/serverconfigchecks.php on line 226

Changing to PHP 7 - via using the Opensuse repository at http://download.opensuse.org/repositories/devel:/languages:/php/openSUSE_Leap_42.2/ helped to overcome this error.

However, be aware of the fact that changing to PHP 7 globally implies a lot of consequences - e.g changing database code in older programs from the the "mysql" to the "mysqli" interface. (Off topic: As long as one wants to use PHP via Apache modules I do not see a way to run both PHP versions in parallel on one Apache2 web server. Things are different with FCGI and PHP-FPM; but I did not experiment with these alternatives, yet. My way to support older programs for the time being actually includes the use of an independent 42.2 LAMP installation on a KVM machine - together with an older 4.3/4.4-version of PhpMyAdmin.]

Another error I stumbled across after installation of PhpMyAdmin 4.7 occured when I tried to use the drop-down boxes for changing pages during the display of large tables. Whenever you use the drop down box a small popup appears complaining about "unmatching tokens".

The recipe to mend this bug is described by the Phpmyadmin developers on the following Internet page:
https://github.com/phpmyadmin/phpmyadmin/commit/5ee4320b7de345062ced7e02aca65417baa8a944

One just has to change some lines (at line nr 796) in the file "/InstallationDirOFPhpmyadminOnWebserver/libraries/DisplayResults.php" as described in the above article :

// Comment the following lines at position 796 and replace with the 2 lines shown 
// $table_navigation_html .= '<form action="sql.php'
// . URL::getCommon($_url_params)
// . '" method="post">';
$table_navigation_html .= '<form action="sql.php" method="post">';
$table_navigation_html .= URL::getHiddenInputs($_url_params);

Good luck with PhpMyAdmin 4.7!