Page MenuHomePhabricator

Html2Wiki error ("Can't use method return value") on fresh MediaWiki with PHP <5.5
Closed, ResolvedPublic

Description

Hi Greg,

Got an issue with the latest version pulled from github. I installed it on a recent MediaWiki and a fresh one too. I get the same error in both cases:

Fatal error: Can't use method return value in write context in /var/www/wiki2/extensions/Html2Wiki/specials/SpecialHtml2Wiki.php on line 1357

If I comment out the relevant code the I can reach the SpecialPages.
I don't know if its an issue or not but I can reproduce the error.

thnx., Sandor

Event Timeline

sfeher assigned this task to freephile.
sfeher raised the priority of this task from to Needs Triage.
sfeher updated the task description. (Show Details)
sfeher subscribed.

Does the content in question have any img tags?

Can you change line 1357 from

if ( $qp->length == 0 ) {

to

if ( ! $qp->length  ) {

and report if the error is still encountered.

Nothing changed.

if ( $qp->length == 0 ) { is line the 1348

The relevant part is the following:

if ( empty( $img->attr('title') ) ) {

$title = str_replace('_', ' ', basename($src));
 $img->attr('title', $title);

}

If I comment out this if then it works.

Has there been any progress on this issue? I am experiencing the same issue on a fresh installation of mediawiki 1.25.1. I am unable to even load the Special:SpecialPages when the Html2Wiki extension is enabled in my LocalSettings.php. I get the following error in my /var/log/httpd/error.log:
PHP Fatal error: Can't use method return value in write context in /var/www/html/extensions/Html2Wiki/specials/SpecialHtml2Wiki.php on line 1357

Line 1356 - 1359 in the SpecialHtml2Wiki.php file is:

1356 $img->attr('src', $src);
1357 if ( empty( $img->attr('title') ) ) {
1358 $title = str_replace('_', ' ', basename($src));
1359 $img->attr('title', $title);

This is a limitation of the EMPTY() function in PHP versions BELOW 5.5.
EMPTY only will check variables, not return values from functions.

So to fix this, in SpecialHTML2Wiki.php change

if ( empty( $img->attr('title') ) ) {		
    $title = str_replace('_', ' ', basename($src));
    $img->attr('title', $title);
}

to

        
if ($img->attr('title') ) {
    $title = str_replace('_', ' ', basename($src));
    $img->attr('title', $title);
}

OR, in theory you should be able to upgrade your php to 5.5+ to fix this issue. I am running 5.3 and used the above workaround instead of upgrading; YMMV.

Reference StackOverflow page on the underlying issue
http://stackoverflow.com/questions/1075534/cant-use-method-return-value-in-write-context

I love this collective triaging above! Patches are also welcome directly on the repository, see https://www.mediawiki.org/wiki/Gerrit/Tutorial :).

Thanks for the fix. I've committed the suggested fix and will push it
upstream asap (30 minutes). Thanks for using this extension and would love
to hear from users.

freephile awarded a token.
freephile set Security to None.
Aklapper renamed this task from Html2Wiki error on a fresh MediaWiki installation to Html2Wiki error ("Can't use method return value") on fresh MediaWiki with PHP <5.5.Sep 19 2015, 11:31 AM