[3.9] Correctly handle objects when storing data in tables with _jsonEncode being set #33633
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request for Issue #33553 .
Summary of Changes
Back-integrate from 4.0-dev to here (staging) the following changes from PR #25761 for fixing bind() with objects in the JTable class:
get_object_vars
if the$src
parameter is an object, so that it is:get_object_vars
.I'm wondering why the 4th step in the above list currently comes before the 1st without this PR.
Testing Instructions
Step 1: On a current staging branch or latest 3.9.x nightly build, switch on ""Debug System" and set "Error Reporting" to "Maximum" or "Development".
Step 2: Add the following code to some administrator view:
E.g. you can add it just before the following line in the users view's default template:
https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_users/views/users/tmpl/default.php#L20
The code creates or updates 2 new contact records in database, using bind() and store(), one contact given as array and the other one as object (stdClass).
Step 3: Navigate to the view modified in the previous step.
In my example: "Users -> Manage" (
administrator/index.php?option=com_users&view=users
).Result: Error 'Cannot use object of type stdClass as array', see issue #33553 and section "Actual result BEFORE applying this Pull Request" below.
Step 4: Check in database if the two contacts have been created.
Result: Only the first contact "Bat Man" has been created.
Step 5: Delete that contact.
Step 6: Apply the patch of this PR.
Step 7: Navigate again to the view modified in the previous step, or reload the page if still there.
Result: No error, the debug output is shown, see section "Expected result AFTER applying this Pull Request" below.
Step 8: Check in database if the two contacts have been created.
Result: Both contacts "Bat Man" and "John Doe" have been created.
Actual result BEFORE applying this Pull Request
Storing data fails with error 'Cannot use object of type stdClass as array'.
The line number may be different to the one shown in the screenshot because that screenshot was made when testing PR #33558 which I had made for 3.10).
Expected result AFTER applying this Pull Request
Storing data succeeds.
The debug output is shown.
Documentation Changes Required
None.
Additional information
This change doesn't need to be merged up into 4.0-dev since it has been applied there already, see PR #25761 . The unit tests are implemented differently there.
I.e. when merging this up and getting conflicts, just chose to use the existing 4.0-dev code for these when resolving.