Fix remaining PHP7 compatibility problems

Bug #1693559 reported by Mark Nielsen
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mahara
Fix Released
Medium
Cecilia Vela Gurovic

Bug Description

Mahara 16.10.4.

Used https://github.com/JakubOnderka/PHP-Parallel-Lint to lint the Mahara codebase, found these issues:

------------------------------------------------------------
Parse error: mahara/auth/saml/extlib/simplesamlphp/vendor/openid/php-openid/Tests/Auth/OpenID/StoreTest.php:699
    697| $db->query("USE $temp_db_name");
    698|
  > 699| $store =& new Auth_OpenID_MDB2Store($db);
    700| if (!$store->createTables()) {
    701| $this->fail("Failed to create tables");
Unexpected 'new' (T_NEW)
------------------------------------------------------------
Parse error: mahara/lib/elastica/lib/Elastica/Filter/Bool.php:13
    11| * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-filter.html
    12| */
  > 13| class Bool extends BoolFilter
    14| {
    15| }
Fatal error: Cannot use 'Bool' as class name as it is reserved
------------------------------------------------------------
Parse error: mahara/lib/elastica/lib/Elastica/Query/Bool.php:13
    11| * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
    12| */
  > 13| class Bool extends BoolQuery
    14| {
    15| }
Fatal error: Cannot use 'Bool' as class name as it is reserved
------------------------------------------------------------
Parse error: mahara/lib/elastica/lib/Elastica/Transport/Null.php:11
     9| * @author James Boehmer <email address hidden>
    10| */
  > 11| class Null extends NullTransport
    12| {
    13| }
Fatal error: Cannot use 'Null' as class name as it is reserved
------------------------------------------------------------

There is also another tool that finds several other errors in the codebase, https://github.com/sstalle/php7cc - in particular this one will error:

File: search/internal/lib.php
> Line 1281: Removed regular expression modifier "e" used
    preg_replace('/&(#x?)?([A-Za-z0-9]+);/e', '_decode_entities("$1", "$2", "$0", $newtable, $exclude)', $text);

There is another modifier "e" usage, but looks like it is only used in a 2009 upgrade step. There are MANY more warnings, deprecations and errors reported.

Yet another tool to check compatibility is https://github.com/wimg/PHPCompatibility which mostly reports the same information as php7cc, but it is harder to use. It does however have support for PHP7.1.

Cheers!

Tags: php7
Revision history for this message
Kristina Hoeppner (kris-hoeppner) wrote :

Hi Mark,

Thanks for the report. It seems you know your way around PHP. Do you want to provide a fix for these issues and submit it to our code review system for inclusion into Mahara? You can find more information on how to set up the connection to Gerrit at https://wiki.mahara.org/wiki/Developer_Area/Contributing_Code

Cheers
Kristina

Changed in mahara:
status: New → Triaged
importance: Undecided → Medium
milestone: none → 17.10.0
Revision history for this message
Robert Lyon (robertl-9) wrote :

Hi Mark,

Looking at that output the first Parse error is in a thirdparty plugin that we fetch via 'make ssphp' so we are unable to fix that locally.

The next three Parse errors are for the elastica php plugin (also a thirdparty plugin) which we can fix locally but are at this moment looking to go with a different elasticsearch php plugin so need to decide on that first.

The search/internal/lib.php issue should be fixed up as that is an internal Mahara file

Cheers

Robert

Revision history for this message
Mark Nielsen (polothy) wrote :

We patched our search/internal/lib.php file with:

      return preg_replace_callback('/&(#x?)?([A-Za-z0-9]+);/', function (array $matches) use ($newtable, $exclude) {
          return PluginSearchInternal::_decode_entities($matches[1], $matches[2], $matches[0], $newtable, $exclude);
      }, $text);

Please note that php7cc tool reports a lot of other warnings/errors that I did not paste in. It is likely worth it to at least review them to determine if any action is needed.

Cheers

Changed in mahara:
assignee: nobody → Cecilia Vela Gurovic (ceciliavg)
Revision history for this message
Mahara Bot (dev-mahara) wrote : A patch has been submitted for review

Patch for "master" branch: https://reviews.mahara.org/7824

Revision history for this message
Cecilia Vela Gurovic (ceciliavg) wrote :

attached php7cc result after running in the code for latest master and removing results for 3rd party libraries

Revision history for this message
Cecilia Vela Gurovic (ceciliavg) wrote :

I checked every error message, and there is no need to fix any of them. Find attached the details.

Revision history for this message
Cecilia Vela Gurovic (ceciliavg) wrote :

Robert's comment:

Actually - since we can't rely on $HTTP_RAW_POST_DATA and using 'php://input' is fine for PHP v5+ we should adjust the code and drop the check and make it explicit what we are doing

$rawHTTPdata = file_get_contents('php://input');
...
$payload = $rawHTTPdata;

so future devs don't get confused about what we are doing and php checkers don't complain about bad code.

Note: php://input is not available with enctype="multipart/form-data"

Revision history for this message
Mahara Bot (dev-mahara) wrote :

Patch for "master" branch: https://reviews.mahara.org/7838

Changed in mahara:
status: Triaged → In Progress
Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/7824
Committed: https://git.mahara.org/mahara/mahara/commit/0488ae4d700cd7580828979632667832afa921e6
Submitter: Robert Lyon (<email address hidden>)
Branch: master

commit 0488ae4d700cd7580828979632667832afa921e6
Author: Mark Nielsen <email address hidden>
Date: Wed Jun 14 12:07:34 2017 +1200

Bug 1693559: php7 compatibility issue in search/internal/lib.php file

behatnotneeded
Change-Id: I336bdb523c0ff138351d77f747a233cc390b44af

Revision history for this message
Cecilia Vela Gurovic (ceciliavg) wrote :

Hi Mark,

1 remaining patch is available here https://reviews.mahara.org/7838 if you want to test it.

Cecilia

Revision history for this message
Mahara Bot (dev-mahara) wrote :

Reviewed: https://reviews.mahara.org/7838
Committed: https://git.mahara.org/mahara/mahara/commit/4a292254ab98c2dfd23c4b86bdd0aa534e6da5d0
Submitter: Robert Lyon (<email address hidden>)
Branch: master

commit 4a292254ab98c2dfd23c4b86bdd0aa534e6da5d0
Author: Cecilia Vela Gurovic <email address hidden>
Date: Wed Jun 28 12:59:56 2017 +1200

Bug 1693559: Fixing php7 compatibility errors

Error message:
 Removed "HTTP_RAW_POST_DATA" variable used
Issue:
 http://php.net/manual/en/reserved.variables.httprawpostdata.php
 variable deprecated in php7.
 We need to use the content of php://input instead.

behatnotneeded

Change-Id: Ia2e16fa08dc2dc7cefa980570c7095cb80dbd0c4

Robert Lyon (robertl-9)
Changed in mahara:
status: In Progress → Fix Committed
Robert Lyon (robertl-9)
Changed in mahara:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.