• Resolved Gwyneth Llewelyn

    (@gwynethllewelyn)


    Hello there!

    I’ve stumbled upon something which has been deprecated for ?ons (technically, around 2009…) but which only became deprecated under PHP 7.4 (throws a warning) and finally removed under PHP 8.0 (throws a fatal error): misuse of curly braces.

    The culprit is on file includes/Michelf/Markdown.php on line 800:

    
    $level = $matches[2]{0} == '=' ? 1 : 2;
    

    which should be written in this decade as:

    
    $level = $matches[2][0] == '=' ? 1 : 2;
    

    That’s basically all that needs a fix for PHP 8.0! ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor David Artiss

    (@dartiss)

    Thanks Gwyneth.

    I’m some way off adding in support for PHP 8 ?? However, it does look as if the most recent version of the markdown script has eliminated this issue – I’ll look at getting that added in.

    Thread Starter Gwyneth Llewelyn

    (@gwynethllewelyn)

    Whoops… my post above was a bit premature; it seems that there are more lines needing similar fixes:

    line 1140:
    $token_stack[0] = str_repeat($token{0}, 3-$token_len);
    to
    $token_stack[0] = str_repeat($token[0], 3-$token_len);

    line 1165:
    $em = $token{0};
    to
    $em = $token[0];

    lines 1530-1532:

                   switch ($token{0}) {
                            case "\\":
                                    return $this->hashPart("&#". ord($token{1}). ";");

    to

                   switch ($token[0]) {
                            case "\\":
                                    return $this->hashPart("&#". ord($token[1]). ";");

    Also, the file /wp-readme-parser/includes/Michelf/MarkdownExtra.php requires some additional changes in a similar vein:

    line 163:
    if ($element{0} == '.') {
    to
    if ($element[0] == '.') {

    line 165:
    } else if ($element{0} == '#') {
    to
    } else if ($element[0] == '#') {

    line 434:
    else if ($tag{0} == "\n" || $tag{0} == " ") {
    to
    else if ($tag{0} == "\n" || $tag{0} == " ") {

    line 443:
    else if ($tag{0} == "“) {`
    to
    else if ($tag[0] == "“) {`

    line 481:
    $tag{1} == '!' || $tag{1} == '?')
    to
    $tag[1] == '!' || $tag[1] == '?')

    lines 500-501:

    if ($tag{1} == '/')                     $depth--;
    else if ($tag{strlen($tag)-2} != '/')   $depth++;

    to

    if ($tag[1] == '/')                     $depth--;
    else if ($tag[strlen($tag)-2] != '/')   $depth++;

    line 605:
    return array($original_text{0}, substr($original_text, 1));
    to
    return array($original_text[0], substr($original_text, 1));

    line 617:
    $tag{1} == '!' || $tag{1} == '?')
    to
    $tag[1] == '!' || $tag[1] == '?')

    lines 628-629:

    if ($tag{1} == '/')                     $depth--;
    else if ($tag{strlen($tag)-2} != '/')   $depth++;

    to

    if ($tag{1} == '/')                     $depth--;
    else if ($tag{strlen($tag)-2} != '/')   $depth++;

    line 993:
    $level = $matches[3]{0} == '=' ? 1 : 2;
    to
    $level = $matches[3][0] == '=' ? 1 : 2;

    line 1337:
    if ($classname{0} == '.')
    to
    if ($classname[0] == '.')

    If I find a few more of those, I’ll post them here as well!

    Note that these files come from the PHP Markdown library; this plugin still uses version 1.6.0 of that library, which is far too old; the current version (as of writing) is 1.9.X, which already has all the above changes made, and, of course, adds a lot of bug fixes and extra features. Maybe the next version of Plugin README Parser can be shipped with a more recent version of PHP-Markdown?

    Last but not least: aye, I’m aware that PHP 8.0 is ‘brand new’ for many, but remember that the current code will throw deprecation warnings on PHP 7.4, so it’s also a nice idea to get rid of those…

    Thread Starter Gwyneth Llewelyn

    (@gwynethllewelyn)

    Whoops… sorry, @dartiss, I was in the process of adding a further list of small changes to be made — and that took me well over an hour. In the meantime, once my own message had been submitted, I saw your reply — and I’m glad that you’ve reached the same conclusion ??????

    So my apologies for writing at apparent cross-purposes! Time, alas, is relative…

    In any case: aye, if the PHP Markdown 1.9.0 library is a drop-in replacement of 1.6.0, then I’d say that it’s far easier for you to just do that library upgrade and do not bother with fixing the code manually. I haven’t double-checked Michel’s library, but it seems that, as far as I could see, it really gets rid of those curly braces…

    Plugin Contributor David Artiss

    (@dartiss)

    I agree.

    I’ve logged it now as work to get done in the next release.

    Thread Starter Gwyneth Llewelyn

    (@gwynethllewelyn)

    Hello @dartiss,

    Hmm, it seems that you’ve been neglecting your plugin code even more than I neglect my own plugins here on WP, lol.

    Anyway, this was just a short reminder that, AFAIK, we’re still stuck with Michel’s 1.6.0 version of the Markdown.php (and MarkdownExtra.php)…

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Deprecated usage of curly braces throws fatal error under PHP 8.0’ is closed to new replies.