WordPress.org

Make WordPress Core

Opened 3 months ago

Closed 3 months ago

Last modified 3 months ago

#47395 closed defect (bug) (duplicate)

Countable Error in meta.php

Reported by: 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 3 months ago.
Patch
47395.2.patch (603 bytes) - added by dkarfa 3 months ago.
Code refactoring
43583.diff (614 bytes) - added by mukesh27 3 months ago.
Added is_countable function for PHP 7.3
47395.diff (614 bytes) - added by mukesh27 3 months ago.
Added is_countable function for PHP 7.3

Download all attachments as: .zip

Change History (11)

@dkarfa
3 months ago

Patch

#1 @dkarfa
3 months ago

  • Keywords has-patch added

#2 @SergeyBiryukov
3 months 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
3 months ago

I think is_countable() function added in PHP 7.3

Version 0, edited 3 months ago by dkarfa (next)

@dkarfa
3 months ago

Code refactoring

#4 @mattgates
3 months 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
3 months ago

Added is_countable function for PHP 7.3

@mukesh27
3 months ago

Added is_countable function for PHP 7.3

#5 @ocean90
3 months 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
3 months 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
3 months 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.