Page 1 of 1

A general question about ALL addons

Posted: Thu May 04, 2023 10:04 am
by mhsuffolk
A general question about ALL addons.
Where an addon uses a deprecated function from functions.php, database.php and possibly others, can that function be copied into a file within the addon just for it’s use?
If so:
1. Is there a rule of thumb as to which addon page to put it e.g the main page that the addon displays?
2. If the same function is copied into 2 different addons, will this cause a problem?

Re: A general question about ALL addons

Posted: Thu May 04, 2023 10:47 am
by ecartz
I think it would be easier to rewrite the add-on not to use the deprecated function. But you can of course load it if you want, removing the deprecation line.

1. Not really, as different add-ons operate differently. What will work in one may not work in another.
2. Yes. But you can wrap it in function_exists to avoid that. E.g.

Code: Select all

if (!function_exists('named_whatever')) {
  function named_whatever() {
  }
}
Note that currently, the deprecated functions are loaded automatically. You can expect that to change around 1.0.9.1 or so. But right now, this wouldn't accomplish anything, as the deprecated version of the function would get loaded anyway.

If you just want to make the deprecation messages go away, you can change your error reporting. E.g. from the default to

Code: Select all

error_reporting(E_ALL & ~E_DEPRECATED);
That will work now but the add-on will stop working in 1.0.9.1 or whenever we stop loading the deprecated functions automatically. If you add the function_exists code and the function definition to the add-on, then it would keep working.

Note that if an autoloaded class were deprecated, then the process would be simpler. As autoloaded classes are loaded when needed.

To summarize, yes, this is possible. No, it is not recommended. No, there is not a standard on how to do this. Individual stores can turn off the deprecation messages, but this can hide the problem. In 1.0.9.1 or so, the problem will become more acute, as the functions will move from deprecated to obsolete. You can use function_exists to make an add-on forwardly compatible so that it keeps working after the functions are removed.

Re: A general question about ALL addons

Posted: Thu May 04, 2023 3:49 pm
by Kofod95
I can, of course, only speak for myself, but I plan on updating my add-ons for 1.0.9.0(-ish) as soon as time allows, and replace the functions with classes. For my simple stuff at least, I see no reason to keep the functions, rather than just use the new classes.

//Daniel