Under some PHP configs, passing the return value of a method to empty() can cause a fatal error. Thus, this segment in AddThisScriptManager.php

if (!empty($this->addthis->getTwitterVia())) {
  $addthis_share['passthrough']['twitter']['via'] = $this->addthis->getTwitterVia();
}
if (!empty($this->addthis->getTwitterText())) {
  $addthis_share['passthrough']['twitter']['text'] = $this->addthis->getTwitterText();
}

can trigger the following error:

Fatal error: Can't use method return value in write context in addthis/classes/Services/AddThisScriptManager.php on line 229

The attached patch corrects this by saving the method return values to variables before using empty().

CommentFileSizeAuthor
AddThisScriptManager-fatal-error.patch985 bytesmuriqui
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

raphaelhuefner’s picture

Thank you for the patch, @muriqui !

I encountered the same issue.

This patch resolved it for me!

All PHP versions prior to 5.5.0 are affected.

See http://www.php.net/manual/en/function.empty.php

Note:
Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). Instead, use trim($name) == false.

and

Changelog
Version: 5.5.0
Description: empty() now supports expressions, rather than only variables.

It worked on my local dev machine (PHP 5.5.18) without the patch, but after deploying to the server (PHP 5.3.5), it blew up. (Obviously, I should've had the same PHP version on my local as on the server.)

matason’s picture

Status: Active » Reviewed & tested by the community

Thank you @muriqui

I tested the patch on addthis-7.x-4.x-dev, it applies cleanly and fixes the fatal error.

  • gisle committed 1157f27 on 7.x-4.x authored by muriqui
    Issue #2529436 by muriqui: Fatal error in AddThisScriptManager.php
    
matglas86’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.