Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#47395 closed defect (bug) (duplicate)

Countable Error in meta.php

Reported by: mattgates's profile mattgates Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Options, Meta APIs Keywords: has-patch
Focuses: Cc:

Description

Warning: count(): Parameter must be an array or an object that implements Countable in wp-includes/meta.php on line 210

This error prevents any posts from being updated. It seems it is erroring because $old_value may not always be an array.

This is the original line that causes errors:

if ( count( $old_value ) == 1 ) {

The fix checks to see if $old_value is an object or array:

if ( (is_array($old_value) || is_object($old_value)) && count( $old_value ) == 1 ) {


After fix is implemented, everything seems to work fine.

Attachments (4)

47395.patch (597 bytes) - added by dkarfa 6 years ago.
Patch
47395.2.patch (603 bytes) - added by dkarfa 6 years ago.
Code refactoring
43583.diff (614 bytes) - added by mukesh27 6 years ago.
Added is_countable function for PHP 7.3
47395.diff (614 bytes) - added by mukesh27 6 years ago.
Added is_countable function for PHP 7.3

Download all attachments as: .zip

Change History (11)

@dkarfa
6 years ago

Patch

#1 @dkarfa
6 years ago

  • Keywords has-patch added

#2 @SergeyBiryukov
6 years ago

  • Keywords needs-refresh added
  • Milestone changed from Awaiting Review to 5.3

We could use the is_countable() polyfill added in #43583.

#3 @dkarfa
6 years ago

I think is_countable() function added in PHP 7.3 . How to deal with the previous version?

Last edited 6 years ago by dkarfa (previous) (diff)

@dkarfa
6 years ago

Code refactoring

#4 @mattgates
6 years ago

is_countable works best and takes care of the two codes. Appreciate the update! Hopefully see it in the core! Every time WordPress gets an update, i have to add this code in there for PHP 7.3.

@mukesh27
6 years ago

Added is_countable function for PHP 7.3

@mukesh27
6 years ago

Added is_countable function for PHP 7.3

#5 @ocean90
6 years ago

  • Keywords needs-refresh removed
  • Milestone 5.3 deleted
  • Resolution set to duplicate
  • Severity changed from blocker to normal
  • Status changed from new to closed
  • Version 5.2.1 deleted

Duplicate of #46660.

#6 @dkarfa
6 years ago

  • Keywords needs-refresh added
  • Severity changed from normal to blocker
  • Version set to 5.2.1

Hey @mattgates
is_countable is available in WP core from 4.9.6 https://developer.wordpress.org/reference/since/4.9.6/ but my point was that if you using any PHP lower version i.e. 7.2 or 5.6 then you will get Fatal error

#7 @ocean90
6 years ago

  • Component changed from Posts, Post Types to Options, Meta APIs
  • Keywords needs-refresh removed
  • Severity changed from blocker to normal
  • Version 5.2.1 deleted
Note: See TracTickets for help on using tickets.