7

In updating an extension to support Joomla 3.x we've run into a few cases where the signature for a function has changed since 2.5 and results in a Strict standards warning.

For example in the JTable class the _getAssetParentId() had changed from

protected function _getAssetParentId($table = null, $id = null)
{
    ...
}

to this in Joomla 3.x:

protected function _getAssetParentId(JTable $table = null, $id = null)
{
    ...
}

It's a small difference but, it's enough to throw up the warning.

Looking at other extensions that support Joomla 2.5 and 3.0 using a single class file they seem to simply ignore the problem.

Obviously, if we fix the warning for 3.x then 2.5 installs with throw the warning…

"Solutions" that aren't an option for us include:

  • using two separate version specific class files
  • turning off the warnings

How do you resolve this conflict?

3 Answers 3

9

At work we try to resolve all PHP warnings, errors and strict standards violations. In situations like this, where the signatures are different, there's no way to resolve it other using two separate, version specific class files. I'm curious though why that's not an option for you?

Version specific class files are actually simple to implement, but a bit harder to maintain, since you'll be updating some code in multiple places. The best thing to do in this situation, IMO, is to have a root src/ folder that holds all your component classes for autoloading, then have any 2.5 or 3.x version specific classes in an overrides/$VERSION folder. You can then setup the autoloader to look in the appropriate places in the appropriate order, based on current version.

I really wish there was an easier way, but PHP doesn't allow dynamic method overloading where you can make the signatures match.

1
  • For extensions we make publicly available it's not an issue, we fix for the latest Joomla version and let the older version deal with the warnings. The extension in question though is for some of our customers that have an extremely high "security" requirement that any third party extensions must be able to run under strict without warnings. It looks like we'll have two versions going forward.
    – Craig
    Apr 23, 2014 at 22:02
4

To my knowledge, you can't solve this strict warning. Because the signatures will always be different in either 2.5 or 3.x.

Either fix it for 3.x and ignore in 2.5 or vice versa.

In a productive enviroment, you should never see this warning anyway as you should only show strict warnings in development settings.

1
  • Yep, this was our thinking, it looks like we'll have two versions going forward.
    – Craig
    Apr 23, 2014 at 22:03
1

There is a major problem with the state of PHP, some servers still use 5.2, while others stay safe at 5.3 or 5.4. There are also some that stay current at 5.5.

This leads to a major problem in "what to support" If you go by the market of the various versions, I would say 5.2 is the most widely used, but insecure. 5.3 and 5.4 are what Joomla looks for in 3, however if a user is in 5.5 the strict standard warnings may be different then the other versions.

Although PHP does not go over the top with the errors, as in it still "works" its warning that the way its done is not how the current version is meant to handle it, but will still work. So for most developers, Notice's and Strict Standards warnings can be mostly ignored since if you fix one you may trigger another in a different PHP version.

Removing them all is best for an OCD developer. Obvious errors should be fixed, but ones like you describe would lead to focusing Joomla to one PHP version to much, leading to much more work to upgrade its PHP version as well.

The only true fix to this is in Joomla's "bootstrap" to test for the PHP version and load files based on that, this could lead to doubling the Joomla base install size, as well as being way more work then should be done for errors that do not actually break any site. Don Gilbert's answer goes into this into some more detail.

My answer is kind of odd, but I feel it can help others understand the total mess PHP is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.