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?
A general question about ALL addons
-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: A general question about ALL addons
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.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 toThat 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.
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() {
}
}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);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.
- Kofod95
- Senior Contributor
- Posts: 748
- Joined: Sat Feb 06, 2021 7:38 pm
- Phoenix Version: 1.0.8.20
- Has thanked: 99 times
- Been thanked: 179 times
Re: A general question about ALL addons
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
//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
Here are a lot of corns: Phoenix user guide