I recently upgraded to php5.4 in a local development environment and the heartbeat stream began throwing strict checking errors.

Strict warning: Non-static method HeartbeatMessagePool::getInstance() should not be called statically, assuming $this from incompatible context in flag_heartbeat_message->_load_content() (line 266 of /home/ross/projects/srcom/sites/all/modules/heartbeat/modules/heartbeat_plugins/plugins/

There were other contexts in which this error arose for the heartbeat.module on line 661, which is the same code as line 266 above.

heartbeat.module line 660.

function heartbeat_activity_load($uaid) {
  return HeartbeatMessagePool::getInstance()->getMessage($uaid);

Proposed resolution

My proposal for resolving this problem is to make the constructor of the HeartbeatMessagePool class a public function. That way we can use the following approach to accessing the data:

Fix for

  function _load_content($content_id) {
      $heartbeatMessage = new HeartbeatMessagePool();
      $heartbeatActivity = $heartbeatMessage->getInstance()->getMessage($content_id);
      return is_numeric($content_id) ? $heartbeatActivity : NULL;

Fix for heartbeat.module

function heartbeat_activity_load($uaid) {
  $heartbeatMessage = new HeartbeatMessagePool();
  return $heartbeatMessage->getInstance()->getMessage($uaid);

Remaining tasks

I've tested this out locally, and the above solution seems to work. I'm not, however, certain if there is a security reason for making this class constructor private. If so, a different solution would need to be found.

Members fund testing for the Drupal project. Drupal Association Learn more


rogical’s picture

You may make a patch if possible, then users will test it easily.

Stalski’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Status: Active » Needs review

I was just reading the differences to php5.4. And especially the line "Added class member access on instantiation (e.g. (new foo)->bar()) support."
Adding brackets around does not help? like "return (HeartbeatMessagePool::getInstance())->getMessage($uaid);"

The code proposed here is not the same as what I need. The getInstance is a singleton.

I did fix/improve something in the code now and that is the synthax of "static public MyClass" versus "public static MyClass".

Also please use the dev version since there are a lot of things fixed and I need some people testing things out.
So just maybe with the code change the problem is fixed and HeartbeatMessagePool can stay a singleton.

Thx in advance

Stalski’s picture

Status: Needs review » Postponed (maintainer needs more info)

Can somebody update me on this?

radj’s picture

I'm using the dev download dated 2012-Jul-31 and the error did go away.

Xano’s picture

Issue tags: -php5.4 +PHP 5.4

Fixing tag.

Xano’s picture

Issue summary: View changes

Added fixes for the

esbenvb’s picture

Here's a patch to fix the problem for those who still run 1.0 and don't want to break anything by updating to 1.1.