-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[5.3] php warning in BackupcodesModel #45170
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_this is an AI generated explanation_ The warning Only the first byte will be assigned to the string offset occurs because $temp1 is being treated as a string, and assigning a value to $temp1[$i] attempts to modify a specific character (byte) of the string. However, the value being assigned (random_int(0, 99999999)) is an integer, which is incompatible with this operation. Root Cause: In PHP, when you use array-like syntax (e.g., $temp1[$i]) on a variable that has not been explicitly declared as an array, PHP may treat it as a string. In this case, $temp1 is being treated as a string, and $temp1[$i] is interpreted as modifying a specific character of the string. Since random_int(0, 99999999) generates an integer, PHP raises a warning because you cannot assign an integer to a specific byte of a string. Fix: To resolve this issue, you need to explicitly declare $temp1 as an array before using it. This ensures that $temp1[$i] is treated as an array element rather than a string offset. Explanation of the Fix: Explicit Declaration: $temp1 = []; ensures that $temp1 is treated as an array from the start. This avoids PHP's automatic type juggling, which might treat $temp1 as a string if it is not explicitly declared. Assigning Values: $temp1[$i] = random_int(0, 99999999); now correctly assigns the random integer to the $ith index of the $temp1 array. Summary: This fix ensures that $temp1 is treated as an array, eliminating the warning and allowing the code to function as intended. Signed-off-by: BrianTeeman <[email protected]>
7 tasks
4 tasks
Contributor
|
I have tested this item ✅ successfully on e49ece5 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/45170. |
1 similar comment
Contributor
|
I have tested this item ✅ successfully on e49ece5 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/45170. |
Contributor
|
RTC This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/45170. |
Member
|
Thanks! |
Contributor
Author
|
Thanks |
brianteeman
added a commit
to brianteeman/joomla-cms
that referenced
this pull request
Mar 23, 2025
### Summary of Changes There is a check in the Author column to display the author name if the id is not 0 else to display the author as None I believe this check to be incorrect. When a user is deleted from the users table the created_by in the content table is untouched so the condition in the query is never passed. This PR changes the condition to check for the author_name in the featured articles and this way we can satisfy the condition and are able to display the author as None _This PR is the same as joomla#45170 but for the featured articles view_ ### Testing Instructions Create two users Create featured articles with each user Delete one of the users Signed-off-by: BrianTeeman <[email protected]>
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
this is an AI generated explanation
The warning Only the first byte will be assigned to the string offset occurs because $temp1 is being treated as a string, and assigning a value to $temp1[$i] attempts to modify a specific character (byte) of the string. However, the value being assigned (random_int(0, 99999999)) is an integer, which is incompatible with this operation.
Root Cause:
In PHP, when you use array-like syntax (e.g., $temp1[$i]) on a variable that has not been explicitly declared as an array, PHP may treat it as a string. In this case, $temp1 is being treated as a string, and $temp1[$i] is interpreted as modifying a specific character of the string. Since random_int(0, 99999999) generates an integer, PHP raises a warning because you cannot assign an integer to a specific byte of a string.
Fix:
To resolve this issue, you need to explicitly declare $temp1 as an array before using it. This ensures that $temp1[$i] is treated as an array element rather than a string offset.
Explanation of the Fix:
Explicit Declaration:
$temp1 = []; ensures that $temp1 is treated as an array from the start. This avoids PHP's automatic type juggling, which might treat $temp1 as a string if it is not explicitly declared. Assigning Values:
$temp1[$i] = random_int(0, 99999999); now correctly assigns the random integer to the $ith index of the $temp1 array.
Summary:
This fix ensures that $temp1 is treated as an array, eliminating the warning and allowing the code to function as intended.
Testing Instructions
Code review or use the cypress integration tests for mfa with php 8.4
npx cypress run --spec '.\tests\System\integration\administrator\components\com_users\Mfa.cy.js'
Actual result BEFORE applying this Pull Request
php warning in the logs
PHP Warning: Only the first byte will be assigned to the string offset in D:\repos\j51\administrator\components\com_users\src\Model\BackupcodesModel.php on line 258Expected result AFTER applying this Pull Request
no php wanring
Link to documentations
Please select:
Documentation link for docs.joomla.org:
No documentation changes for docs.joomla.org needed
Pull Request link for manual.joomla.org:
No documentation changes for manual.joomla.org needed