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

[REF] Fix strstr deprecation in CustomDataByType class #25230

Merged
merged 1 commit into from
Dec 29, 2022

Conversation

braders
Copy link
Contributor

@braders braders commented Dec 28, 2022

Overview

Fix strstr deprecation in CustomDataByType class.

Before

The following error could be logged:

[28-Dec-2022 19:55:40 Europe/London] PHP Deprecated:  strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in .../civicrm/CRM/Custom/Form/CustomDataByType.php on line 51

After

Ensure value passed to strstr is an empty string rather than null, avoiding deprecated functionality.

@civibot
Copy link

civibot bot commented Dec 28, 2022

(Standard links)

@demeritcowboy
Copy link
Contributor

I don't know what the circumstance is but does this actually work? Won't you have the same problem with trim() on the next line? Maybe up at line 36 would be better?

@demeritcowboy
Copy link
Contributor

Does it even make sense that a request variable would contain CRM_Core_DAO::VALUE_SEPARATOR? Or that it could ever be an array when it specifies String in the retrieve()? I'm wondering if these lines are left over from some older version?

@braders
Copy link
Contributor Author

braders commented Dec 29, 2022

I don't know what the circumstance is but does this actually work? Won't you have the same problem with trim() on the next line? Maybe up at line 36 would be better?

strstr('', CRM_Core_DAO::VALUE_SEPARATOR) will always return false, so we don't need to worry about the same issue occuring on line 52 (as it'll never be reached if $this->_subType is null).

That said, I'm equally happy to move to line 36, which also ensures we're passing a string to setGroupTree.

Does it even make sense that a request variable would contain CRM_Core_DAO::VALUE_SEPARATOR? Or that it could ever be an array when it specifies String in the retrieve()? I'm wondering if these lines are left over from some older version?

It's a very valid question. I've been doing some playing and can't find a case where $this->_subType would be a string seperated by CRM_Core_DAO::VALUE_SEPARATOR. That said, I couldn't say with certainty that I've tested every route, and it's also possible that extensions are calling civicrm/custom with a CRM_Core_DAO::VALUE_SEPARATOR subType param.

So I guess the question is how comfortable you are that this could be removed? Another option would be to add a call to CRM_Core_Error::deprecatedWarning within the if statement, specifying that the subType parameter should be comma-seperated.

@demeritcowboy
Copy link
Contributor

Good thinking. I like the deprecation notice.
I note it was added at https://github.com/civicrm/civicrm-core/pull/6011/files, and it appears to be copy/paste from CRM/Custom/Form/CustomData.php.
Also noting that in the template it's used as

if (subType) {
  dataUrl += '&subType=' + subType;
}

so is really unlikely to be an array.

So I'm pretty confident that deprecating is valid.

@demeritcowboy
Copy link
Contributor

Looks like I merged an earlier one too quickly without seeing the same thing although it's slightly different since the param can come from anywhere, but has the same trim() issue on the next line. The downside of PRs that have 18 disconnected things in them...

@eileenmcnaughton eileenmcnaughton merged commit 1fd8984 into civicrm:master Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants