-
-
Notifications
You must be signed in to change notification settings - Fork 824
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 e-notice in APIv3 Profile Test on PHP8 #21143
Conversation
(Standard links)
|
api/v3/Profile.php
Outdated
@@ -604,6 +604,7 @@ function _civicrm_api3_buildprofile_submitfields($profileID, $optionsBehaviour, | |||
*/ | |||
} | |||
} | |||
$profileFields[$profileID] = is_array($profileFields[$profileID]) ? $profileFields[$profileID] : []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point in the test, $profileFields is an empty array, so I would expect is_array($profileFields[$profileID])
to give an undefined index. In fact if you put an echo 'hi';
right after this line it doesn't output, so it's giving an E_NOTICE which is inadvertently fixing it by fullfilling the fail. If you put a var_dump($apiResult);
in assertAPIFailure itself you can see this is what's happening.
Further, if there's no valid reason for this situation, would throwing an exception directly here be a better thing to do, because always converting to a valid thing might potentially hide other issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@demeritcowboy the problem is that it is not an empty array on php8 it is NULL for $profileFields[$profileID]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$profileFields is an empty array, so $profileFields[$profileID] gives an ENOTICE when you use is_array on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right sorry got confused, does my update work for you @demeritcowboy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I'm going to put merge-ready because I'm confused about a couple things, but if someone wants to merge I won't object.
- It seems like a (unintended?) change from dev/core#2743 fix api v3 to not unnecessarily load options #21099. Before it used to say "'1000' is not a valid option for field uf_group_id", and now, with this patch, it says "Invalid value for profile_id", which in this case yes is more accurate.
- I'm still wondering about my comment from before: If there's never a valid reason for
$profileFields[$profileID]
to be null here, then converting it to a valid value instead of throwing an exception might end up hiding something else. In either case it's a change from before, because what it used to do before, funnily enough, was to actually create an entry for 1000 inside the array, i.e. after the uasort$profileFields = [1000 => NULL]
, and now after the uasort$profileFields = [1000 => []]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm - I think - yeah good points - but I guess if we are going to do a better fix it would be fine to do it in master & if no-one actually cares enough to do it then I guess that's fine if there is no reproduceable regression.
So I'm happy to merge this & maybe someone will fix more better in master
Remove e-notice issue found by dave d
d1bbb16
to
3413e58
Compare
Overview
This fixes an e-notice error on php 8 unit tests on 5.40, 5.41, master branches
Before
Test e-notice
After
Test passes on php8
ping @eileenmcnaughton @totten