Page 1 of 1

Remove globals for core back-end dispatch

Posted: Sun Oct 01, 2017 4:23 pm
by cmb
Hi everybody!

There are several global variables which are there to support CMSimple_XH's core back-end (aka. administration) dispatch, namely: $phpinfo, $settings, $sysinfo, $validate, $xh_backups, $xh_change_password, $xh_do_validate, $xh_pagedata and $xh_plugins. These are initialized from a given GET or POST parameter, but in the following only used to set $f to an appropriate value. Of course, the detour of using global variables for this purpose is nonsentical; the respective GET or POST parameters can be checked in ::setBackendF() directly.

Simply changing the respective code (and so removing these globals) might break extensions, though, particularly since some of these globals are not documented at all, and the others are inconspicuously documented as private. Therefore I suggest to add prominent deprecation warnings for XH 1.8.0 and to finally remove them in 2.0.0 without any replacement.

Note that I'm planning to update our developer documentation from master from time to time[1], so deciding on this rather sooner than later would give extension writers more time to become aware of the scheduled change, and to act accordingly.

Thoughts?

Re: Remove globals for core back-end dispatch

Posted: Mon Oct 02, 2017 11:21 am
by manu
Just go for it. A BC break might be easily recognized & fixed.

Re: Remove globals for core back-end dispatch

Posted: Mon Nov 27, 2017 11:09 pm
by cmb
manu wrote:Just go for it. A BC break might be easily recognized & fixed.
Well, guess we have to postpone respective changes until https://github.com/cmsimple-xh/cmsimple-xh/issues/340 would be solved.

Re: Remove globals for core back-end dispatch

Posted: Tue Nov 28, 2017 8:01 am
by Tata
cmb wrote:... respective GET or POST parameters can be checked in ::setBackendF() directly... Therefore I suggest to add prominent deprecation warnings for XH 1.8.0 and to finally remove them in 2.0.0 without any replacement...
Again the same question like in pwf_xh post:
Can'r a checking wether globals are defined in a plugin solve the transition phase at least?
I mean something like:

Code: Select all

if(...plugin is called...){
if (...globals are defined in plugin...){
echo "deprecation-warning" ignore globals from plugin
}else{
use (...globals from core...)}
} 

Re: Remove globals for core back-end dispatch

Posted: Tue Nov 28, 2017 11:56 am
by cmb
Tata wrote:Can'r a checking wether globals are defined in a plugin solve the transition phase at least?
There is no way to detect any access to a global variable during runtime[1]. That is the main reason why global variables are a bad idea for an API. Even a static analysis is not really possible.
Tata wrote:I mean something like:
[…]
There appears to be a misunderstanding. This is not about global variables which are defined by plugins, but rather about some global variables which are defined by the core, and may be used by plugins.

[1] Actually, there are some exceptions, but these do not apply in this case.