Problem
Type hints are like laws set by PHP functions to demand what type of arguments must be passed in. Before Elgg 1.8.6, violations of these laws went completely undetected, so even careful plugin authors missed them and left incorrect code in their plugins.
The Elgg 1.8.6 release escalated these violations to fatal errors. You may recognize these in your server error logs by messages like:
"Argument number passed to function() must be type, other_type given".
Solutions
The Elgg team realized the 1.8.6 change was premature, and Elgg 1.8.7 will downgrade these errors to warnings, but in the meantime, a site owner running 1.8.6 has a few options:
How to fix a plugin (for programmers)
The most common type hint violation in Elgg is when authors assume get_entity() will return an ElggEntity (in many cases it returns false), then pass this value into a function that requires an entity, such as elgg_view_entity_icon().
Instead, authors must test the return value of get_entity() before treating the value as an ElggEntity:
$entity = get_entity($guid);
if ($entity) {
// $entity is an ElggEntity
} else {
// $entity is false
}
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
I'd personally use
instead of
but that may as well be an overkill.
Yes, the type/subtype should be checked and elgg_instanceof() make that code easier to read. A simple boolean check works as a patch if you don't know the types/subtypes expected.