-
-
Notifications
You must be signed in to change notification settings - Fork 840
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
Fix PHP warnings #4278
base: master
Are you sure you want to change the base?
Fix PHP warnings #4278
Conversation
E_WARNING: Trying to access array offset on value of type bool ./inc/Ui/Recent.php(165)
E_WARNING: Undefined array key 3 in ./inc/media.php(1700) E_WARNING: Trying to access array offset on value of type null in ./inc/media.php(1700) This happens when the media manager is called with ns parameter set to a value higher than the last namespace defined in the wiki. Fixes dokuwiki#4276
When the media manager is called with ns parameter set to a value higher than the last namespace defined in the wiki, the non-existing namespace is not added to the hierarchy. This behavior is not consistent with what happens when the namespace's name is lower. In this case, an entry is inserted in the tree at the appropriate location. Fixed by appending the temporary namespace at the end of the tree if it was not inserted by the search loop. Fixes dokuwiki#4276
if ( | ||
$pos >= count($data) || | ||
($data[$pos]['level'] <= $level + 1 && Sort::strcmp($data[$pos]['id'], $tmp_ns) > 0) | ||
) { | ||
array_splice($data, $pos, 0, [['level' => $level + 1, 'id' => $tmp_ns, 'open' => 'true']]); | ||
$insert = true; |
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.
Comment by @fiwswe, originally posted in dregad@de301a3#r141568139
You might want to reset $insert = false; here for the next foreach loop iteration? But I'm not very sure what this code is really trying to do, so this might be wrong.
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.
Unless I'm missing something, I believe this is not necessary because the foreach processes the elements of the "current namespace" (e.g. aaa:bbb:ccc
-> aaa
, bbb
and ccc
), and the while loop checks for each element if it's present in the media directory's structure.
Therefore, if we start inserting an entry in $data at any point in that second loop because it was not found (say, aaa
, then by definition nothing exists below that newly created tree branch, so we will keep inserting until we reach the end of the foreach loop (bbb
and then ccc
).
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.
Ok, if that is what this code is doing, your explanation makes sense.
PS. Sorry about commenting in the wrong repository. I was reacting to a GitHub notification about a change and failed to check.
Fixes #4276
Includes a fix for another PHP warning I did not open an issue for.