Problem/Motivation
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/flagattachment.inc).
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 flagattachment.inc
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.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | heartbeat-strict_error_with_heartbeatmessagepool-1498436-6.patch | 382 bytes | esbenvb |
Comments
Comment #1
rogical commentedYou may make a patch if possible, then users will test it easily.
Comment #2
Stalski commentedI 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
Comment #3
Stalski commentedCan somebody update me on this?
Comment #4
radj commentedI'm using the dev download dated 2012-Jul-31 and the error did go away.
Comment #5
xanoFixing tag.
Comment #5.0
xanoAdded fixes for the flagattachment.inc.
Comment #6
esbenvb commentedHere'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.