[wp-trac] [WordPress Trac] #59318: Block Themes Fatal Error in PHP 8.1 When Referring To Missing Template Parts

WordPress Trac noreply at wordpress.org
Tue Jun 11 17:02:13 UTC 2024


#59318: Block Themes Fatal Error in PHP 8.1 When Referring To Missing Template
Parts
-------------------------------------------------+-------------------------
 Reporter:  TJNowell                             |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  6.6
Component:  Themes                               |     Version:  6.3.1
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests php81       |     Focuses:  php-
  gutenberg-merge                                |  compatibility
-------------------------------------------------+-------------------------
Changes (by hellofromTonya):

 * keywords:  has-patch has-unit-tests php81 gutenberg-merge needs-testing
     => has-patch has-unit-tests php81 gutenberg-merge


Comment:

 == Test Report

 Patch tested: 6.6 Beta 2 or current `trunk`.

 === Steps to Reproduce or Test

 Setup:
 1. Use PHP 8.1 or higher.
 2. Use WP 6.3.4 when attempting to reproduce the reported issue.
 3. Use WP 6.6 Beta 2 or newer to test if the bug is fixed in Core.


 Testing Steps:
 1. Open `wp-content/themes/twentytwentyfour/templates/home.html` file in
 your favorite code editor.
 2. In the footer template-part, change the `slug` to something that does
 not exist:
 {{{
 <!-- wp:template-part
 {"slug":"doesnotexistfooter","area":"footer","tagName":"footer"} /-->
 }}}
 3. `$is_debug` needs to be `false`. Two ways to accomplish this:
    a. Set `WP_DEBUG` to `false` in `wp-config.php`.
    b. Set `WP_DEBUG_DISPLAY` to false` in `wp-config.php`.
    c. Temporarily modify the
 [https://core.trac.wordpress.org/browser/tags/6.3.4/src/wp-includes/blocks
 /template-part.php#L110 following line of code] in `wp-includes/blocks
 /template-part.php` to hardcode it to `false`. This approach lets you keep
 `WP_DEBUG` and `WP_DEBUG_DISPLAY` set to `true` to further see the
 deprecation notice in the front-end.
 {{{
 $is_debug = false; //WP_DEBUG && WP_DEBUG_DISPLAY;
 }}}
 4. Open the home page in the front. 🐞 A Deprecation notice is thrown
 (viewable in the server logs, debug.log, and/or on the screen in your
 browser).

 === Expected Results
 When testing a patch to validate it works as expected:
 - ✅ What should happen when running the test

 When reproducing a bug:
 - ❌ PHP Deprecation notice should be thrown.

 === Environment
 * OS: macOS
 * Web Server: nginx
 * PHP: 8.3
 * WordPress: 6.3.4 to reproduce the error and then 6.6 Beta 2 to validate
 the fix.
 * Browser: Firefox 126.0
 * Theme: TT4
 * Plugins:
    * Beta Tester
    * Core Rollback

 Notes:

 I used step 3c as I want to see the PHP deprecation in the browser and in
 the `debug.log` file. I made sure my `wp-config.php` had these constants:
 {{{
 if ( ! defined( 'WP_DEBUG' ) ) {
         define( 'WP_DEBUG', true );
 }

 define( 'WP_DEBUG_LOG', true );
 define( 'WP_DEBUG_DISPLAY', true );
 define( 'SCRIPT_DEBUG', true );

 define( 'WP_ENVIRONMENT_TYPE', 'local' );
 }}}

 ==== Actual Results
 When reproducing a bug/defect using 6.3.4:
 - ❌ PHP Deprecation notice is thrown.

 {{{
 Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of
 type array|string is deprecated in
 /Volumes/DevSSD/Local/releaseparty/app/public/wp-includes/formatting.php
 on line 868
 }}}

 When testing the bugfix patch using 6.6 Beta 2:
 - ✅ No longer throwing the PHP Deprecation notice.

 === Observations

 Yes, the committed fix resolves the reported issue. However, passing
 `null` to a non-nullable parameter is a deprecation notice and not a fatal
 error introduced in PHP 8.1. https://php.watch/versions/8.1/internal-func-
 non-nullable-null-deprecation

 As @poena
 [https://github.com/WordPress/gutenberg/pull/54354#issuecomment-1892044231
 originally reported in the fix's PR], there is another issue with a higher
 error level:

 {{{
 Warning: Attempt to read property "content" on null in
 /Volumes/DevSSD/Local/releaseparty/app/public/wp-includes/blocks/template-
 part.php on line 73
 }}}

 This happens because `$block_template` is being used as an object when
 `get_block_file_template()` returns `null`. An additional guard check is
 needed.

 This issue will need a separate fix. It'll need a separate Gutenberg issue
 and fix as well as tests.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59318#comment:15>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list