1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Fixed PHP7. Fatal Error: Method XenForo_BbCode_TextWrapper::__toString()

Discussion in 'Resolved Bug Reports' started by GliX, Dec 8, 2015.

Tags:
  1. GliX

    GliX Active Member

    Error at PHP 7.0.

    Error Info

    ErrorException: Fatal Error: Method XenForo_BbCode_TextWrapper::__toString() must not throw an exception -library/XenForo/Template/Abstract.php(265) : eval()'d code:0
    Generated By: Unknown Account, 51 minutes ago

    Stack Trace
    #0 [internal function]: XenForo_Application::handleFatalError()
    #1 {main}
     
  2. GliX

    GliX Active Member

    Error at PHP 7.0, occurs in RSS feeds with threads, which use CODE bb-code.

    Error Info
    ParseError: Invalid numeric literal - library/XenForo/BbCode/Formatter/Base.php(1420) : highlighted code:5
    Generated By: Unknown Account, 29 minutes ago

    Stack Trace
    PHP:
    #0 /var/www/demo.local/library/XenForo/BbCode/Formatter/Base.php(1420): highlight_string('<?php\n[Tue Oct ...', true)
    #1 /var/www/demo.local/library/XenForo/BbCode/Formatter/Base.php(745): XenForo_BbCode_Formatter_Base->renderTagPhp(Array, Array, Object(XenForo_BbCode_Formatter_Base))
    #2 /var/www/demo.local/library/XenForo/BbCode/Formatter/Base.php(652): XenForo_BbCode_Formatter_Base->renderValidTag(Array, Array, Array)
    #3 /var/www/demo.local/library/XenForo/BbCode/Formatter/Base.php(565): XenForo_BbCode_Formatter_Base->renderTag(Array, Array, 0)
    #4 /var/www/demo.local/library/XenForo/BbCode/Formatter/Base.php(546): XenForo_BbCode_Formatter_Base->renderTreeElement(Array, Array, 0)
    #5 /var/www/demo.local/library/XenForo/BbCode/Formatter/Base.php(526): XenForo_BbCode_Formatter_Base->renderSubTree(Array, Array)
    #6 /var/www/demo.local/library/XenForo/BbCode/Parser.php(505): XenForo_BbCode_Formatter_Base->renderTree(Array, Array)
    #7 /var/www/demo.local/library/XenForo/ViewPublic/Forum/View.php(64): XenForo_BbCode_Parser->render('\xD0\xA1\xD0\xB5\xD0\xB3\xD0\xBE\xD0\xB4\xD0\xBD\xD1\x8F ...', Array)
    #8 /var/www/demo.local/library/XenForo/ViewRenderer/Abstract.php(227): XenForo_ViewPublic_Forum_View->renderRss()
    #9 /var/www/demo.local/library/XenForo/ViewRenderer/Rss.php(31): XenForo_ViewRenderer_Abstract->renderViewObject('XenForo_ViewPub...', 'Rss', Array, 'forum_view')
    #10 /var/www/demo.local/library/XenForo/FrontController.php(604): XenForo_ViewRenderer_Rss->renderView('XenForo_ViewPub...', Array, 'forum_view', NULL)
    #11 /var/www/demo.local/library/XenForo/FrontController.php(158): XenForo_FrontController->renderView(Object(XenForo_ControllerResponse_View), Object(XenForo_ViewRenderer_Rss), Array)
    #12 /var/www/demo.local/index.php(13): XenForo_FrontController->run()
    #13 {main}
     
  3. Chris D

    Chris D XenForo Developer Staff Member

    I'm unable to reproduce this with PHP 7.

    Are you able to share the exact post content within the PHP tag that is causing this?
     
  4. Mike

    Mike XenForo Developer Staff Member

    Can you reproduce this with all add-ons disabled on the default style?
     
  5. GliX

    GliX Active Member

    Yes. Default style, no add-ons.
     
  6. Chris D

    Chris D XenForo Developer Staff Member

    If you can reproduce it, what are the actual reproduction steps?
     
  7. GliX

    GliX Active Member

  8. GliX

    GliX Active Member

  9. Mike

    Mike XenForo Developer Staff Member

    This and your other bug report are almost certainly the same thing and related to the PHP BB code specifically.
     
  10. Chris D

    Chris D XenForo Developer Staff Member

    We're not running PHP 7 here, yet, nor do I have it on this PC at the moment, but thanks for the examples I will try it with PHP 7 later.
     
  11. Chris D

    Chris D XenForo Developer Staff Member

    Indeed, they are, so I have merged the threads.

    This is the error that triggers while trying to post the problem content.

    This is the error when trying to view that content if it already exists.

    I have confirmed this with PHP 7.0.1-dev, though I haven't actually updated this for some time, which I will do shortly. It's possible it's a bug in PHP itself, especially as the ParseError is happening within a core PHP function which we don't actually have any control over, short of working out what cases the parse error and sanitising or escaping it.

    EDIT: Now running 7.0.2-dev, and the issue is still present.

    EDIT 2: Simpler reproduction case:
    PHP:
    09
    o_O

    As far as I can work out so far, the specific change in PHP 7 is this:
    Which relates to: http://phpsadness.com/sad/31

    EDIT 3: Have reported it as a PHP bug: https://bugs.php.net/bug.php?id=71086

    The behaviour here seems unexpected. It is caused by a fairly valid change in PHP 7, but not one I think that should affect the highlight_string function.
     
    Last edited: Dec 10, 2015
    SneakyDave, Bob and Brogan like this.
  12. Chris D

    Chris D XenForo Developer Staff Member

    It has indeed been confirmed as a PHP bug and it has been fixed. I haven't tested yet to see if that fix is available in the latest nightly build, but for most people I guess we'll see this in PHP 7.0.2.

    In terms of how we handle this in XF we are catching this parse error and falling back to rendering a standard [CODE] tag.

    If this bug is affecting you, find the following in library/XenForo/BbCode/Formatter/Base.php:
    PHP:
    $content highlight_string($contenttrue);
    And replace with:
    PHP:
    try
    {
       
    $content highlight_string($contenttrue);
    }
    catch (
    Throwable $e)
    {
       
    // Workaround for PHP (7.0.0) bug #71086
       
    return $this->renderTagCode($tag$rendererStates) ;
    }
    EDIT: The nightly build has indeed fixed this:
    Code:
    PHP 7.0.2-dev (cli) (built: Dec 11 2015 20:13:30) ( NTS )
     
    Last edited: Dec 25, 2015
    sadiq6210, SneakyDave, shello and 9 others like this.
  13. The Forum Heroes

    The Forum Heroes Well-Known Member

    Confirming your fix works. Thanks Chris!
     
  14. maxicep

    maxicep Active Member

    Fixed, thanks..

    (php 7.0.1)
     
  15. Chris D

    Chris D XenForo Developer Staff Member

    Eagle, eva2000 and RoldanLT like this.

Share This Page