[wp-trac] [WordPress Trac] #55257: map_deep() function incompatibility with incomplete objects in PHP 8.0+

WordPress Trac noreply at wordpress.org
Fri Feb 25 12:14:00 UTC 2022


#55257: map_deep() function incompatibility with incomplete objects in PHP 8.0+
--------------------------+-----------------------------
 Reporter:  codex-m       |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Formatting    |    Version:  5.9.1
 Severity:  major         |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Incomplete objects (`__PHP_Incomplete_Class`) used to have no issues with
 `map_deep()` before PHP 8.0 because it ignores any incomplete object. With
 PHP 8.0 - this now returns fatal error and PHP cannot continue processing.
 This disrupts an otherwise normal processing (before PHP 8.0).

 Example of uncaught error in debug.log are as follows:

 `PHP Fatal error:  Uncaught Error: The script tried to modify a property
 on an incomplete object. Please ensure that the class definition
 "SuperCustomXyz" of the object you are trying to operate on was loaded
 _before_ unserialize() gets called or provide an autoloader to load the
 class definition in /wp/wp-includes/formatting.php:4998`

 For the `map_deep()` function to be truly compatible with PHP 8.0 ( as it
 was with earlier PHP versions) - can we modify this to check for
 incomplete objects? And if the value to be processed is an incomplete
 object - we skipped processing. This will make the function to behave like
 it was being used before PHP 8.0. As a result - the function still returns
 an array with incomplete objects as it was used to be working.

 This issue can be reproduced as follows:

 Environment:

 * PHP 8.0
 * WordPress 5.9.1
 * Create a dummy test PHP script as follows in the WP root directory:

 {{{#!php
 <?php
 require_once 'wp-load.php';

 $test_data = 'a:2:{i:0;O:14:"SuperCustomXyz":1:{s:17:" SuperCustomXyz
 x";s:4:"test";}s:8:"testdata";a:2:{s:1:"a";i:1;s:1:"b";i:2;}}';
 $unserialized = maybe_unserialize($test_data);

 $res = map_deep($unserialized, 'stripslashes_from_strings_only');
 print_r($res);
 }}}

 Using PHP 8.0+ - this now returns fatal error. In PHP 7.4 and below (where
 most of the WordPress sites are still using), this returns an array with
 an incomplete object:


 {{{
 Array
 (
     [0] => __PHP_Incomplete_Class Object
         (
             [__PHP_Incomplete_Class_Name] => SuperCustomXyz
             [ SuperCustomXyz x] => test
         )

     [testdata] => Array
         (
             [a] => 1
             [b] => 2
         )

 )
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/55257>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list