Make WordPress Core

Opened 4 years ago

Closed 3 years ago

#48528 closed defect (bug) (duplicate)

warning in wp-includes/class.wp-scripts.php:454: Cannot assign an empty string to a string offset

Reported by: dpacks's profile dpacks Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.2.4
Component: Script Loader Keywords: php8
Focuses: Cc:

Description

When sending an empty value to wp_localize_script() a warning is issued stating:
Cannot assign an empty string to a string offset

How to reproduce:
call wp_localize_script() like this:

<?php
wp_localize_script('my_valid_handle', 'my_variable_name', '');

Analysis:
Sending an empty value for a variable is perfectly legit so there is no problem with the input.
The problem lies here: The code at line 449 treats $l10n forcefully as an array but the code at 454 wrongfully assumes $l10n is an array without checking.

Change History (8)

#1 @nofearinc
4 years ago

The wp_localize_script docs treat $l10n as an array, which is why an empty string is not a valid default value. I'm not sure what's the use case for an empty value in general, but have you tested an empty array instead?

#2 @SergeyBiryukov
3 years ago

Related: #25280, #29722, #51108.

Just noting that passing a string value to wp_localize_script() is now causing a warning in PHP 8.0 Beta 2:

Warning: Only the first byte will be assigned to the string offset in wp-includes/class.wp-scripts.php on line 492

Last edited 3 years ago by SergeyBiryukov (previous) (diff)

#3 @SergeyBiryukov
3 years ago

  • Keywords php8 added

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


3 years ago

#5 @hellofromTonya
3 years ago

  • Milestone changed from Awaiting Review to 5.6

Per yesterday's scrub conversation in slack, this ticket is part of the 5.6 PHP8 scope. Moving into the milestone.

#6 @jrf
3 years ago

Duplicate of #29722 ?

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


3 years ago

#8 @johnbillion
3 years ago

  • Milestone 5.6 deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #29722.

Note: See TracTickets for help on using tickets.