|How to make onContentAfterSave compatible with Joomla 2.5 AND 3.x|
Joomla 3 introduced a very annoying change, $article parameter in onContentAfterSave event is now passed by value, while in Joomla 1.6.-2.5 it was passed by reference and having the same method definition for both will cause an error in one of them. Depends on how you approach it, e.g. if you have parameter defined by reference, call_user_func_array that works behind the scenes to fire plugin events will return false and since your plugin won't work (without any php error).So, a coding challenge is to make a plugin that is compatible with both popular joomla series. Take a bit of brain, add a large portion of poetry and here is a way to do it:
In the plugin file create an intermediate class that contains you actual code with one exception - rename onContentAfterSave to something else
Now conditionally define a class with your actual plugin name using code like this:
Yes, you can do that in PHP.
And again - no ninjas were harmed while performing this magic.