WordPress.org

Make WordPress Core

Opened 2 months ago

Last modified 3 weeks ago

#52622 reviewing defect (bug)

Fix PHP Warning on PHP7.2 in class-wp-http-curl.php

Reported by: sjoerdlinders Owned by: SergeyBiryukov
Milestone: 5.8 Priority: normal
Severity: normal Version: 5.6.2
Component: HTTP API Keywords: has-patch
Focuses: administration, coding-standards Cc:

Description

Added the default settings parameter 'decompress' with the default value 'false'.

<?php
$defaults = array(
                        'method'      => 'GET',
                        'timeout'     => 5,
                        'redirection' => 5,
                        'httpversion' => '1.0',
                        'blocking'    => true,
                        'headers'     => array(),
                        'body'        => null,
                        'cookies'     => array(),
                        'decompress'  => false,
                );

If this array element is not pre-defined it will result in a warning on line 316:

<?php
if ( true === $parsed_args['decompress'] && ...

Change History (7)

This ticket was mentioned in PR #1036 on WordPress/wordpress-develop by sjoerdlinders.


2 months ago

  • Keywords has-patch added; needs-patch removed

Added the default settings parameter 'decompress' with the default value 'false'.
If this array element is not pre-defined it will result in a warning on line 316:

if ( true === $parsed_argsdecompress? && ...

Trac ticket: https://core.trac.wordpress.org/ticket/52622

#2 @SergeyBiryukov
2 months ago

  • Milestone changed from Awaiting Review to 5.8
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#3 follow-up: @jrf
2 months ago

@sjoerdlinders Out of interest and to document this issue properly:

  • What is the warning you see ?
  • How can the issue be reproduced ?
  • Can this change be safeguarded by adding a unit test which would demonstrate the warning without the fix ?

#4 @desrosj
8 weeks ago

  • Keywords reporter-feedback added

#5 in reply to: ↑ 3 @sjoerdlinders
7 weeks ago

Replying to jrf:

  • What is the warning you see ?

E_NOTICE => Undefined index: decompress
wp-includes/class-wp-http-curl.php (line 315)

if ( true === $parsed_args['decompress'] && ...


This notice is caught by the file 'wp-admin/admin-header.php' (line 197)

$error_get_last = error_get_last(); 

and will add the following 'php-error' class in the admin body tag: (line 205)

$admin_body_class .= ' php-error';

which will show extra header space on the admin page, without the actual notice issue itself.

  • How can the issue be reproduced ?

On a WordPress Multisite (WPMU) setup this notice will be given when you switch to an other domain.

Last edited 7 weeks ago by sjoerdlinders (previous) (diff)

#6 @sjoerdlinders
7 weeks ago

Second change:
Added the default settings parameter 'filename' with a default empty string value .

$defaults = array(
        'method'      => 'GET',
        'timeout'     => 5,
        'redirection' => 5,
        'httpversion' => '1.0',
        'blocking'    => true,
        'headers'     => array(),
        'body'        => null,
        'cookies'     => array(),
        'decompress'  => false,
        'filename'    => '',
);

If this array element is not pre-defined it will result in a E_NOTICE 'Undefined index: filename' on line 306:

'filename' => $parsed_args['filename'],

This can be reproduces and will show exactly the same result problems as discribed in my reply #comment:5

(https://github.com/WordPress/wordpress-develop/pull/1036/)

#7 @sjoerdlinders
3 weeks ago

  • Keywords reporter-feedback removed

Third and final change:
Added the default settings parameter 'stream' with a default null value.

$defaults = array(
        'method'      => 'GET',
        'timeout'     => 5,
        'redirection' => 5,
        'httpversion' => '1.0',
        'blocking'    => true,
        'headers'     => array(),
        'body'        => null,
        'cookies'     => array(),
        'decompress'  => false,
        'stream'      => null,
        'filename'    => '',
);

If this array element is not pre-defined it will result in a E_NOTICE 'Undefined index: stream' on line 299:

if ( $parsed_args['stream'] ) {

This can be reproduces and will show exactly the same result problems as discribed in my reply #comment:5

(https://github.com/WordPress/wordpress-develop/pull/1036/)

Note: See TracTickets for help on using tickets.