2017-11-22, 22:49

Feb 27, 2012 — Notify Users module, ver. 0.5 released — user can choose between sending single message (...) »

2013-01-28, 08:32

19 студзеня 2013 у Гродне трагічна загінуў паэт, журналіст і мой сябар (...) »

2009-10-14, 07:19

The site Litaratura.org is devoted to Belarusian literary works and translations. (...) »

2009-01-12, 20:46

Late November 2008 marked the 20th anniversary of the official founding of the Belarusian (...) »

Registered User Area Log into This Site
Show Credits... Credits
Worthwhile Services
Refresh My Local Time (GMT+1)... Nov 22, 2017 — 22:49
  • France (1)
    Russian Federation (1)
    United States (1)
    __unresolved (1)
  • Today (397)
  • Yesterday (454)
~ / Public Domain Software / How to revert MODx Evo to operation in PHP 5.4 $_
How to revert MODx Evo to operation in PHP 5.4
Click To View A Full Size Image...
2012-03-02, 09:16

MODx Evo site experiences problems while running within newly released PHP 5.4 environment.

PHP 5.4 sets up error reporting level with E_STRICT flag enabled by default thus forcing programmers to follow coding standards. However, this strict PHP behavior breaks execution of MODx Evo code. It applies to those parts of MODx Evo code where non-static methods are called without creating the instance of an object — in such a case MODx Evo site throws „PHP Parse error”. For example, heavily used on every non-trivial MODx site Ditto snippet makes several illegal — in the terms of PHP 5.4 — calls to its methods.

Setting proper error reporting flags for this old-style object-oriented code seems to be the shortest way of resolving the issue.

Disabling E_STRICT flag in .htaccess file does not resolve this issue, bacause MODx Evo itself sets error reporting level with a direct call of error_reporting() function in three different files: config.inc.php, index.php, and manager/index.php. You need to find the call of error_reporting() in those files and replace function’s parameter:

    error_reporting(E_ALL & ~E_NOTICE);

with new set of flags:

    error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);

Now some bad news. The above is far not enough to revert your site to operation.

We also need to make MODx document parser aware of this new assumption made by PHP 5.4 authors. This is very important part because document parser executes both bundled and user-designed snippets.

Open manager/includes/document.parser.class.inc.php, find definition of executeParser() function, and make a change in its prologue from:

    function executeParser() {
        //error_reporting(0);
        if (version_compare(phpversion(), "5.0.0", ">="))
            set_error_handler(array (
                & $this,
                "phpError"
            ), E_ALL);
        else
            set_error_handler(array (
                & $this,
                "phpError"
            ));

to:

    function executeParser() {
        //error_reporting(0);
        if (version_compare(phpversion(), "5.0.0", ">="))
            set_error_handler(array (
                & $this,
                "phpError"
            ), E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
        else
            set_error_handler(array (
                & $this,
                "phpError"
            ));

Details that need to be changed are in red.

Done. Enjoy your MODx Evo site running in PHP 5.4.

Click to show a form...Click to hide the form... Write a comment
  • Required fields are marked with *.
  • Comments are published after the approval of the site owner, who is a human rather than a wind-fast computer program so please be patient.

* Code:
 
Get another image...Enter this code into the appropriate field of the form while submitting an e-mail or a comment. If you have trouble with reading it, generate another...
Haprog
Comment
Re: How to revert MODx Evo to operation in PHP 5.4
Comment #1 on: 2013-02-06, 10:22
Thanks! Just what I was looking for.
Yaroslav
Comment
Re: How to revert MODx Evo to operation in PHP 5.4
Comment #2 on: 2013-03-07, 12:45
Thanx a lot!
Hendrik
Comment
You saved my day
Comment #3 on: 2014-03-14, 08:20
Thanx for your article! You saved my day!