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

str_replace deprecation issue on FieldModel #3350

Closed
robsonsobral opened this issue May 1, 2023 · 2 comments · Fixed by #3361
Closed

str_replace deprecation issue on FieldModel #3350

robsonsobral opened this issue May 1, 2023 · 2 comments · Fixed by #3361
Labels
Bug: Accepted Bug has been confirmed, is reproducible, and ready to work on.

Comments

@robsonsobral
Copy link
Contributor

robsonsobral commented May 1, 2023

Description of the problem

In case of an empty variable, we get a warning.

How To Reproduce
Steps to reproduce the behavior:

  1. Create a member field with type textarea
  2. I'm not sure, but I guess I changed the Text formatting setting afterwards. I'm sorry! I'm not sure;
  3. Leave the field empty for the member being tested;
  4. output the field using {exp:member:custom_profile_data}

A code sample follows:

{exp:member:custom_profile_data member_id="{embed:member_id}" cache="yes"
refresh="30" cache_prefix="h-card--{embed:member_id}"}
        {if mini_bio}
          <div class="p-note h-card__p-note">
              {mini_bio}
          </div>
        {/if}
{/exp:member:custom_profile_data}

Error Messages

Deprecated
str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated

ee/ExpressionEngine/Model/Content/FieldModel.php, line 516

    Severity: E_DEPRECATED

Screenshots / Videos / Template Code

Environment Details:

  • Version: 7.2.15
  • PHP Version 8.2.4
  • MySQL Version [e.g. 5.7]
  • OS: Linux
  • Web Server: nginx

Possible Solution

This can be fixed by replacing:

        if ($tag) {
            return str_replace(LD . $tag . RD, $data, $tagdata);
        }
        $tag = $this->field_name;
        if ($modifier) {
            $tag = $tag . ':' . $modifier;
        }

        return str_replace(LD . $tag . RD, $data, $tagdata);

With:

        if ($tag && $data !== null) {
            return str_replace(LD . $tag . RD, $data, $tagdata);
        }
        $tag = $this->field_name;
        if ($modifier) {
            $tag = $tag . ':' . $modifier;
        }

        return $data !== null
            ? str_replace(LD . $tag . RD, $data, $tagdata)
            : $tagdata;

Additional context

I'm sorry, but I can't dig more into it right now.

@intoeetive
Copy link
Contributor

@robsonsobral what would be the steps to replicate this? Is this coming from an add-on or EE templates?

@robsonsobral
Copy link
Contributor Author

It's on the member module, @intoeetive . I updated the previous message.

@intoeetive intoeetive added the Bug: Accepted Bug has been confirmed, is reproducible, and ready to work on. label May 3, 2023
intoeetive added a commit that referenced this issue May 3, 2023
intoeetive added a commit that referenced this issue May 24, 2023
Resolved #3350 where PHP notice might be shown when parsing empty member field
matthewjohns0n added a commit that referenced this issue Jun 12, 2023
Resolved #3350 where PHP notice might be shown when parsing empty member field
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Accepted Bug has been confirmed, is reproducible, and ready to work on.
Projects
None yet
2 participants