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

Update $company_tagline check for PHP8+ #2430

Merged
merged 2 commits into from
May 30, 2023
Merged

Conversation

anaemnesis
Copy link
Contributor

@anaemnesis anaemnesis commented May 25, 2023

Fixes # #2424

Changes proposed in this Pull Request

As of PHP8, passing null to strlen() is deprecated. The $company_tagline var is assigned to the output of the get_the_company_tagline function, which returns null under certain conditions.

With this change, we're checking that $company_tagline exists: continue if it does, but if it's null or doesn't exist, return early.

Testing instructions

  • Check out branch
  • Create a new job listing with a company tagline
  • Ensure no tagline shows if one is not present, and a tagline shows if one is present

As of PHP8, passing `null` to `strlen()` is deprecated. The `$company_tagline` var is assigned to the output of the `get_the_company_tagline` function, which returns `null` under certain conditions.

With this change, we're checking that `$company_tagline` exists: continue if it does, but if it's `null` or doesn't exist, return early.
@anaemnesis anaemnesis requested a review from a team May 25, 2023 14:11
@anaemnesis anaemnesis self-assigned this May 25, 2023
@anaemnesis anaemnesis linked an issue May 25, 2023 that may be closed by this pull request
Copy link
Contributor

@aaronfc aaronfc left a comment

Choose a reason for hiding this comment

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

Hey! It is looking good!

I am not sure if "company_tagline" could be "0" (a string with just a 0). In that case this condition wouldn't behave the same.

(Check here if you are curious).

If that's something that we don't expect to happen I am ok with the fix. But if this could ever happen I would suggest doing a check like is_null($company_tagline) || 0 === strlen($company_tagline).

Or maybe even 0 === strlen($company_tagline ?? '').

What do you think?

@anaemnesis
Copy link
Contributor Author

anaemnesis commented May 30, 2023

@aaronfc I checked for (string) 0 and couldn't replicate a use-case where it happened, but just in case, I'll go with

if ( is_null( $company_tagline ) || 0 === strlen($company_tagline) ) {
	return;
}

This way, we're checking for null or 0 specifically rather than existence.

Committed a0556d6

To be safe, let's check for `null` or `0` (string) explicitly.
@anaemnesis anaemnesis merged commit 115ef94 into trunk May 30, 2023
@anaemnesis anaemnesis deleted the fix/the_company_tagline_php8 branch May 30, 2023 13:21
@yscik yscik added this to the 1.41.0 milestone Jun 14, 2023
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.

Modifying company_tagline function for compatibility with PHP 8.1
3 participants