Make WordPress Core

Opened 3 years ago

Closed 16 months ago

#54043 closed defect (bug) (invalid)

PHP Fatal Error on the rest api location

Reported by: passam's profile passam Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: REST API Keywords: php80 close
Focuses: Cc:

Description (last modified by sabernhardt)

Here's is the full stack trace. Note, we do not alter core files in any way and it is updated to the latest version (5.8 at time of writing)... Note we recently upgraded to php8

timberry.bplans.com - PHP Fatal error: Uncaught ArgumentCountError: is_numeric() expects exactly 1 argument, 3 given in .../www/wp/wp-includes/rest-api/class-wp-rest-request.php:910
Stack trace:
#0 .../www/wp/wp-includes/rest-api/class-wp-rest-request.php(910): is_numeric('14102', Object(WP_REST_Request), 'id')
#1 .../www/wp/wp-includes/rest-api/class-wp-rest-server.php(976): WP_REST_Request->has_valid_params()
#2 .../www/wp/wp-includes/rest-api/class-wp-rest-server.php(414): WP_REST_Server->dispatch(Object(WP_REST_Request))
#3 .../www/wp/wp-includes/rest-api.php(370): WP_REST_Server->serve_request('/custom-permali...')
#4 .../www/wp/wp-includes/class-wp-hook.php(303): rest_api_loaded(Object(WP))
#5 .../www/wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters('', Array)
#6 .../www/wp/wp-includes/plugin.php(518): WP_Hook->do_action(Array)
#7 .../www/wp/wp-includes/class-wp.php(388): do_action_ref_array('parse_request', Array)
#8 .../www/wp/wp-includes/class-wp.php(750): WP->parse_request('')
#9 .../www/wp/wp-includes/functions.php(1291): WP->main('')
#10 .../www/wp/wp-blog-header.php(16): wp()
#11 .../www/index.php(9): require('/home/saur...')
#12 {main}
 thrown in .../www/wp/wp-includes/rest-api/class-wp-rest-request.php on line 910

Change History (6)

#1 @sabernhardt
3 years ago

  • Component changed from General to REST API
  • Description modified (diff)

#2 @hellofromTonya
3 years ago

  • Keywords close added

Hello @passam,

Welcome to WordPress Core's Trac!

The error message and first entry in the error stack trace give clues:

PHP Fatal error: Uncaught ArgumentCountError: is_numeric() expects exactly 1 argument, 3 given in /home/sauron/code/global/wp/www/wp/wp-includes/rest-api/class-wp-rest-request.php:910

Stack trace:
#0 /home/sauron/code/global/wp/www/wp/wp-includes/rest-api/class-wp-rest-request.php(910): is_numeric('14102', Object(WP_REST_Request), 'id')

You noted that it happened when upgrading to PHP 8. That's a clue too. This sample shows what happens in < PHP 8 and with PHP 8 when the validate_callback is set to is_numeric:

  • PHP 8 throws a Fatal Error
  • <= 7.4.23 throws a Warning

A warning was likely being logged in the site's error logs.

Why is this happening?

A custom endpoint exists in the site (from a plugin, theme, or script) that defines a custom endpoint with the validate_callback set to is_integer.

PHP's `is_numeric()` accepts only 1 argument, i.e. the value to be evaluated.

The REST API Handbook warns of using is_integer as the validation_callback:

You could also pass in a function name to validate_callback, but passing certain functions like is_numeric directly will not only throw a warning about having extra parameters passed to it, but will also return NULL causing the callback function to be called with invalid data.

What to do?

The key is to figure out where the custom endpoint exists and then work with its author to resolve. How to figure out?

  • do a search in the wp-content folder
  • or deactivate plugins one-at-time until the problem goes away (then that's the one causing it)
  • or use the WordPress Support Forums for further help

For resolution, the REST API Handbook recommends using an anonymous function and then within it invoke is_integer().

Notes

I'm marking this ticket as close.

Why? The problem appears to be external to WordPress core itself.

Why not close it? Thinking it would be good for a REST component maintainer to review:

  • if there are further enhancements to be done within core itself to allow using functions like is_integer() as the callback
  • and/or if using rest_is_integer() might be another option, and if yes, then maybe updating the handbook to suggest it as an alternative

though likely both of these are outside scope of this ticket.

#4 @SergeyBiryukov
3 years ago

  • Keywords php8 added

#5 @hellofromTonya
20 months ago

  • Keywords php80 added; php8 removed

#6 @hellofromTonya
16 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

As there's been no further activity on this ticket for 2 years, I'll go ahead and close it as it appears to be a plugin issue.

Thank you @passam! I hope the issue has already been resolved for you. However, if it persists today after deactivating all plugins, then please reopen and share additional information such as how to reproduce it.

Note: See TracTickets for help on using tickets.