erusev / parsedown-extra

Markdown Extra Extension for Parsedown

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Call to undefined method DOMText::getAttribute() in HHVM

GrahamCampbell opened this issue · comments

HHVM 3.4 and 3.6-dev both display have this issue:

Fatal error: Call to undefined method DOMText::getAttribute() in /home/travis/build/BootstrapCMS/CMS/vendor/erusev/parsedown-extra/ParsedownExtra.php on line 477

Yeah, I did notice this earlier. It's quite weird. It seems like an issue with hhvm.

We should skip that check if we're on hhvm so that we can still run parsedown. It's causing my entire test suite to crash atm. :(

Does #43 look like a quick fix for now?

I'd rather have the part of the test that causes the warning removed. Perhaps, we should also report the issue to the hhvm team.

I think they know about it already. They haven't implemented those methods yet, that's all.

Another option would be to not support hhvm until the issue is resolved.

If you did that, people would just move away from your library, inc me. moving my laravel wrapper.

This might never be resolved in hhvm btw. They might be choosing not to support this.

Ok, I'll see what I can do.

Also, I just tried out my "fix", and it doesn't work.

commented

We are having these problems reported over at OctoberCMS too. Correct me if I'm wrong here guys, but a text node (DOMText) shouldn't contain attributes anyway.

if ($DOMDocument->documentElement->hasAttributes() && $DOMDocument->documentElement->getAttribute('markdown') === '1')

Checking if said element "hasAttributes()" first might be a more logical fix? Also, the next else expression would be wise to check for child nodes too.

elseif ($DOMDocument->documentElement->hasChildNodes())

Full method is here.

If HHVM are being really conservative, they might not have included hasAttributes() on a DOMText node either, because "Duh it's a text node" so this can also be tested:

if ((!$DOMDocument->documentElement instanceof \DOMText) && $DOMDocument->documentElement->getAttribute('markdown') === '1')

@daftspunk Could you create a pull request?

commented

@hkdobrev Can you confirm that any of these proposals work first? I am unaffected by this issue and am unable to confirm.

I have this issue with OctoberCMS, I have tried solutions proposed by daftspunk. After a bit of research I've found out what follows:

  1. adding hasAttributes() check does not help, hhvm paradoxically returns true for text nodes, so I get same error, no getAttribute method on DOMText,
  2. adding:
if (method_exists($DOMDocument->documentElement, 'getAttributes') && $DOMDocument->documentElement->getAttribute('markdown') === '1')) 

or

if ((!$DOMDocument->documentElement instanceof \DOMText) && $DOMDocument->documentElement->getAttribute('markdown') === '1')

check helps with missing DOMText::getAttribute, but causes new error:

"Cannot access property on non-object" on line 473 of /srv/www/workbench/october/vendor/erusev/parsedown-extra/ParsedownExtra.php

which is

$DOMDocument->replaceChild($DOMDocument->firstChild->firstChild->firstChild, $DOMDocument->firstChild);

Commenting out this line causes stack overflow on line 496:

$elementText .= $this->processTag($nodeMarkup);

Adding elseif ($DOMDocument->documentElement->hasChildNodes()) check proposed by daftspunk does not seem to help. Even doing something as stupid as:

if (property_exists($DOMDocument, 'firstChild') && property_exists($DOMDocument->firstChild, 'firstChild') && property_exists($DOMDocument->firstChild->firstChild, 'firstChild')) {
        $DOMDocument->replaceChild($DOMDocument->firstChild->firstChild->firstChild, $DOMDocument->firstChild);
    } 

does not help with this loop. HHVM 3.5.1 here.

commented

Thanks @keiosweb, the issue appears to be more complex than I thought. Might need attention from the author or from someone with more intimate knowledge of the logic.

@keiosweb Thanks for the comment. It's an important issue. I'll look into it as soon as can. Hopefully, later this month.

commented

Did this end up fixed?

No idea. I've lost interest.

@daftspunk It probably is - HHVM should be quite mature by now - I'd guess it has "learned" to execute the code without producing an error.

@keiosweb where can i add this
if (method_exists($DOMDocument->documentElement, 'getAttributes') && $DOMDocument->documentElement->getAttribute('markdown') === '1'))

i am having the same issue please... am using codeigniter