Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-863: PHP Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated #865

Merged
merged 3 commits into from
Feb 29, 2024

Conversation

anubisthejackle
Copy link
Contributor

@anubisthejackle anubisthejackle commented Feb 29, 2024

Note: To minimize the impact on the rest of the Fieldmanager fields, this change is localized to the TextArea field, since that appears to be where the issue is occurring.

Fixes Issue

PHP Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated

Description of Change

To address the issue of PHP deprecation errors when a default_value field is not set and defaults to null, we have modified the logic in the printing of fields within the WP admin area. Specifically, in scenarios where a default value is not set, which leads to a null return value, a ternary operation or a direct assignment now ensures that esc_textarea receives an empty string instead of null. This change prevents htmlspecialchars() from throwing a deprecation notice due to receiving a null value.

The modification was implemented in the handling of default values within the Fieldmanager_TextArea class to circumvent the deprecation notice. It's crucial to emphasize that the default behavior for handling default values remains unaltered to prevent unintended side effects in other areas of the application.

Use Case Affected

This change impacts any site using fields that extend Fieldmanager_TextArea, specifically in scenarios where the default_value is not explicitly set. The new default value will be an empty string and not null as it was previously.

Comments/Suggestions

  • @renatonascalves has played a crucial role in suggesting the approach of defaulting to an empty string within the Fieldmanager_Textarea class to address this deprecation issue.

Acceptance Criteria

  • With no default value set, resulting in a null return value, esc_textarea will now receive an empty string instead of null.
  • The approach to handling default values should not be fundamentally altered to avoid unintended consequences in other parts of the application.

@anubisthejackle anubisthejackle marked this pull request as ready for review February 29, 2024 13:55
Copy link
Contributor

@mogmarsh mogmarsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mboynes mboynes merged commit b815ceb into main Feb 29, 2024
5 checks passed
@mboynes mboynes deleted the fix/issue-863/handle-null-default-value-php-deprecation branch February 29, 2024 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants