[wp-trac] [WordPress Trac] #47441: WP_Ajax_Upgrader_Skin Bug: "unique" error code is always 1

WordPress Trac noreply at wordpress.org
Fri May 31 05:11:18 UTC 2019


#47441: WP_Ajax_Upgrader_Skin Bug: "unique" error code is always 1
-----------------------------+-----------------------------
 Reporter:  jrf              |      Owner:  (none)
     Type:  defect (bug)     |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  Upgrade/Install  |    Version:  4.6
 Severity:  normal           |   Keywords:  has-patch
  Focuses:                   |
-----------------------------+-----------------------------
 The concatenation and plus/minus signs in PHP have the
 [https://www.php.net/manual/en/language.operators.precedence.php same
 operator precedence].

 With that in mind, have a look at the following code in `wp-admin/includes
 /class-wp-ajax-upgrader-skin.php`:
 {{{#!php
 <?php
 // Count existing errors to generate an unique error code.
 $errors_count = count( $this->errors->get_error_codes() );
 $this->errors->add( 'unknown_upgrade_error_' . $errors_count + 1, $string
 );
 }}}


 The "unique" error code, will basically always be `1` as the concatenation
 is done first, the resulting string which doesn't start with a number is
 then cast to an integer - `0` - before the addition of `1` is done and `0
 + 1` will **always** be `1`.

 See: https://3v4l.org/EYuU8

 While this is a bug in its own right as is, as of PHP 8.0, the operator
 precedence of concatenation will be lowered, with deprecation notices
 being thrown as of PHP 7.4 for unparenthesized expressions containing an
 '.' before a '+' or '-'.


 Also see:
 * https://wiki.php.net/rfc/concatenation_precedence

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47441>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list