WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#37683 closed defect (bug) (fixed)

$collate and $charset can be undefined in wpdb::init_charset()

Reported by: robsat91 Owned by: pento
Milestone: 4.6.1 Priority: normal
Severity: normal Version: 4.6
Component: Database Keywords: has-patch fixed-major
Focuses: Cc:
PR Number:

Description

Hello!

After updating from 5.3.1 to 4.6 i got an error:
Notice: Undefined variable: collate in /Users/robert/Nettsider/wp/ehc-wordpress/webroot/wordpress/wp-includes/wp-db.php on line 752

It seems that the reason for the error is that i did not set the constant "DB_COLLATE" in wp-config.php. This worked before, but not in 4.6.

Is there some issue with fallback values if some constants are not set maybe?

Best regards, Robert Sather.

Attachments (2)

37683.patch (646 bytes) - added by Frozzare 3 years ago.
37683.2.patch (434 bytes) - added by Frozzare 3 years ago.

Download all attachments as: .zip

Change History (16)

#1 @pento
3 years ago

  • Component changed from General to Database
  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 4.6.1

Thanks for the bug report, @robsat91!

You're correct, this warning will occur if DB_COLLATE isn't set - we'll get this fixed up it 4.6.1.

#2 @robsat91
3 years ago

Wow, that was fast.
Perfect, thanks mate! :)

Good job with 4.6 btw, noticing the speed increase already!

#3 @ocean90
3 years ago

  • Summary changed from Getting "Notice: Undefined variable: collate" after update to 4.6 to $collate and $charset can be undefined in wpdb::init_charset()

Introduced in #36917.

Another report mentions that is also happens for $charset.

@Frozzare
3 years ago

#4 @Frozzare
3 years ago

  • Keywords has-patch added; needs-patch removed

Attached a possible fix that only runs determine_charset when a charset and collate isset.

#5 @swissspidy
3 years ago

  • Owner set to pento
  • Status changed from new to assigned

The patch resolves the issue for me.

@pento Leaving final review to you. Feel free to commit afterwards.

#6 @pento
3 years ago

  • Keywords needs-refresh added

Thanks for the patch, @Frozzare!

I think a better solution would be to set $charset and $collate to empty strings at the start of ::init_charset(). ::determine_charset() should be called, even when $collate is not set, as the collation can change based on the charset. It doesn't really matter either way if the method is called when $charset is empty, I'm inclined to call it just to not increase code complexity.

Also, $this->charset and $this->collate need to be set, even when the local vars are empty, or similar warnings will occur in ::set_charset().

Finally, a note to committers: please don't commit any patches on this ticket without my review - #37689 may be related, which I'm currently investigating. The outcome of that ticket may have an effect on the best solution for this ticket.

@Frozzare
3 years ago

#7 @Frozzare
3 years ago

@pento thanks for the feedback! Attached a new patch with empty string variables.

#8 @swissspidy
3 years ago

  • Keywords needs-refresh removed

This ticket was mentioned in Slack in #core by swissspidy. View the logs.


3 years ago

#10 @SergeyBiryukov
3 years ago

#37815 was marked as a duplicate.

This ticket was mentioned in Slack in #core by jeremyfelt. View the logs.


3 years ago

#12 @pento
3 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 38439:

Database: Ensure that variables are defined correctly.

There were some cases where some local variables in wpdb::init_charset() could be undefined when they were used.

Props Frozzare.
Fixes #37683 for trunk.

#13 @pento
3 years ago

  • Keywords fixed-major added
  • Resolution fixed deleted
  • Status changed from closed to reopened

#14 @pento
3 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 38440:

Database: Ensure that variables are defined correctly.

There were some cases where some local variables in wpdb::init_charset() could be undefined when they were used.

Merge of [38439] to the 4.6 branch.

Props Frozzare.
Fixes #37683.

Note: See TracTickets for help on using tickets.