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

Prevent Undefined array key 1 warnings #127

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

fiwswe
Copy link
Contributor

@fiwswe fiwswe commented Aug 6, 2024

These warnings occur due to the incorrect assumption that explode(…, $match, 2) will return at least an array of length 2:

E_WARNING: Undefined array key 1
/var/www/dokuwiki/lib/plugins/blog/syntax/archive.php(29)
#0 /var/www/dokuwiki/lib/plugins/blog/syntax/archive.php(29): dokuwiki\ErrorHandler::errorHandler()
#1 /var/www/dokuwiki/inc/parser/handler.php(298): syntax_plugin_blog_archive->handle()
#2 /var/www/dokuwiki/inc/Parsing/Lexer/Lexer.php(269): Doku_Handler->plugin()
#3 /var/www/dokuwiki/inc/Parsing/Lexer/Lexer.php(196): dokuwiki\Parsing\Lexer\Lexer->invokeHandler()
#4 /var/www/dokuwiki/inc/Parsing/Lexer/Lexer.php(146): dokuwiki\Parsing\Lexer\Lexer->dispatchTokens()
#5 /var/www/dokuwiki/inc/Parsing/Parser.php(113): dokuwiki\Parsing\Lexer\Lexer->parse()
#6 /var/www/dokuwiki/inc/parserutils.php(234): dokuwiki\Parsing\Parser->parse()
#7 /var/www/dokuwiki/inc/parserutils.php(198): p_get_instructions()
#8 /var/www/dokuwiki/inc/parserutils.php(520): p_cached_instructions()
#9 /var/www/dokuwiki/inc/parserutils.php(299): p_render_metadata()
#10 /var/www/dokuwiki/inc/common.php(262): p_get_metadata()
#11 /var/www/dokuwiki/doku.php(101): pageinfo()
#12 {main}

Fix this by suppressing the warnings.

Note: Another fix might be to use the DokuWiki sexplode() function instead of explode().

@Klap-in
Copy link
Member

Klap-in commented Aug 7, 2024

Please do not use suppression but fix the errors instead please. For that purpose sexplode() is added to DokuWiki indeed. (As it is added to last two recent versions, it might affect backwards compatibility, but at least 2 releases is ok)

$flags = explode('&', $flags);
list($match, $refine) = explode(' ', $match, 2);
list($ns, $rest) = explode('?', $match, 2);
list($match, $refine) = sexplode(' ', $match, 2, null);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I'm not sure null is the correct default here. Please critically check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants