I am receiving a large number of undefined array key warnings with the following stack trace:
PHP message: Warning: Undefined array key 0 in /var/www/wp-includes/plugin.php on line 661  [wp-content/plugins/cart-rest-api-for-woocommerce/includes/cocart-rest-functions.php:72 apply_filters_deprecated(), wp-content/plugins/cart-rest-api-for-woocommerce/includes/api/cocart/v2/cart/class-cocart-cart-controller.php:2949 cocart_deprecated_filter(), wp-includes/rest-api/class-wp-rest-server.php:1457 CoCart_Cart_V2_Controller->get_public_cart_schema(), wp-includes/rest-api/class-wp-rest-server.php:1398 WP_REST_Server->get_data_for_route(), wp-includes/rest-api/class-wp-rest-server.php:1227 WP_REST_Server->get_data_for_routes(), wp-includes/rest-api/class-wp-rest-server.php:1143 WP_REST_Server->get_index(), wp-includes/rest-api/class-wp-rest-server.php:990 WP_REST_Server->respond_to_request(), wp-content/plugins/woocommerce/includes/cli/class-wc-cli-runner.php:63 WP_REST_Server->dispatch(), /usr/local/bin/wp/vendor/wp-cli/wp-cli/php/class-wp-cli.php:337 WC_CLI_Runner::after_wp_load(), /usr/local/bin/wp/vendor/wp-cl...
I think this all starts because
WC_CLI_Runner::after_wp_loadinitializes the REST API
$argsto be an array of arguments, and it incorrectly assumes that
CoCart_Cart_V2_Controller->get_public_cart_schemabe updated to accomocate this behavior from
What are you doing to create this error?
It’s not happening after a specific user action. Based on the stack trace it seems to be triggered by WooCommerce’s CLI task runner.
So I think this is happenning when the WP_CLI is intialized and
The runner runs on any GET request made via CLI and even though it is blocked by checking if it is a WooCommerce endpoint, it’s still possibly triggering this.
Mind testing this release to see if it solves it for you?
Unfortunately this did not solve the issue for me. I updated to the
3.7.8-beta.1release on my development site. The deploy cleared the logs and the warnings started again.
I see this line was updated:
cocart_deprecated_filter( 'cocart_cart_schema', $schema['properties'], '3.1.0', 'cocart_cart_items_schema', __( 'Changed for the purpose of not overriding default properties.', 'cart-rest-api-for-woocommerce' ) );
The array index 0 still doesn’t exist in
According to the docs,
apply_filters_deprecatedexpects to receive an array of arguments that would normally be passed to a filter function. So I think
array( $schema['properties'] )would do the trick.
Here’s an example from WordPress core:
Ah I see. Thank you for getting back to me so quickly.
Hopefully this release will work then.
- You must be logged in to reply to this topic.