Make WordPress Core

Opened 2 years ago

Closed 5 months ago

Last modified 5 months ago

#55777 closed defect (bug) (worksforme)

Undefined index: type in /wp-includes/rest-api.php

Reported by: mte90's profile Mte90 Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.9.3
Component: REST API Keywords: reporter-feedback
Focuses: rest-api Cc:

Description

I am getting this errors in the PHP log but is not clear why they are here or why WordPress fails.
I am getting them on the home page but I think that wordpress should avoid the undefined index issue, maybe also the notice for rest_validate_value_from_schema should inform about the rest that generated.

[19-May-2022 09:53:49 UTC] PHP Notice:  Undefined index: type in /wp-includes/rest-api.php on line 2095
[19-May-2022 09:53:49 UTC] PHP Notice:  Undefined index: type in /wp-includes/rest-api.php on line 2110
[19-May-2022 09:53:49 UTC] PHP Notice:  rest_validate_value_from_schema è stato richiamato <strong>in maniera scorretta</strong>. La parola chiave dello schema "tipo" per stockStatus può contenere solamente i tipi predefiniti: array, object, string, number, integer, boolean, e null. Leggi <a href="https://wordpress.org/support/article/debugging-in-wordpress/">Debugging in WordPress</a> per maggiori informazioni. (Questo messaggio è stato aggiunto nella versione 5.5.0.) in /wp-includes/functions.php on line 5775
[19-May-2022 09:53:49 UTC] PHP Notice:  Undefined index: type in /wp-includes/rest-api.php on line 2119

Change History (5)

#1 @Mte90
2 years ago

  • Version set to 5.9.3

#2 @costdev
2 years ago

  • Keywords reporter-feedback added

Hi @Mte90, I've just started looking into this.

Can you confirm whether you have another _doing_it_wrong() like this one about the index being required?

La parola chiave dello schema "tipo" per stockStatus è obbligatoria.

This fires if ! isset( $args['type'] ), so I believe it should also be there in your logs.

#3 @Mte90
2 years ago

I don't have in my website a REST with that value, my guess is that is generated by Woocommerce (it is used).

Looking at the code https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes/rest-api.php#L2098:

<?php
if ( ! isset( $args['type'] ) ) {
                /* translators: %s: Parameter. */
                _doing_it_wrong( __FUNCTION__, sprintf( __( 'The "type" schema keyword for %s is required.' ), $param ), '5.5.0' );
        }

        if ( is_array( $args['type'] ) ) {

We check if isset later if it is an array but not together so there is the error.

#4 @Mte90
5 months ago

  • Resolution set to worksforme
  • Status changed from new to closed

I think that we can close it as after all those time I didn't saw that issue anymore.

Also the code changed a bit and now expected an array for that variable https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes/rest-api.php#L2123

#5 @swissspidy
5 months ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.