• Resolved Bence Szalai

    (@grapestain)


    Hi!

    Query Monitor causes a Fatal error as:

    PHP Fatal error: Uncaught TypeError: QMX_Collector_Image_Sizes::filter__wp_get_attachment_image_src(): Argument #2 ($attachment_id) must be of type int, string given, called in /var/www/html/wp-includes/class-wp-hook.php on line 326 and defined in /var/www/html/wp-content/plugins/query-monitor-extend/image-sizes/qmx-image-sizes-collector.php:148

    The reason is that WooCommerce uses a default image when a product does not have one, and this image is the result of a get_option( 'woocommerce_placeholder_image', 0 ) call which returns the image ID as a string which is passed as the first parameter to a subsequent wp_get_attachment_image() call (see the source of wc_placeholder_img() in wp-content/plugins/woocommerce/includes/wc-product-functions.php if interested).

    Please remove the int type constraint from the 2nd argument of QMX_Collector_Image_Sizes::filter__wp_get_attachment_image_src( $image, int $attachment_id, $size ) . On one hand this argument is not used at all in the given function, so the type should not matter, and generally speaking any constraint that can cause such issues should be removed from Query Monitor. On the other hand even if the attachment ID was supposed to be an integer always (which I guess is not the case for many plugins just because how relaxed PHP and WordPress is regarding IDs as integers or strings) a Fatal Error is not the right way to handle such cases.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.