Remove globals for core back-end dispatch

Discussions and requests related to new CMSimple features, plugins, templates etc. and how to develop.
Please don't ask for support at this forums!
Post Reply
cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Remove globals for core back-end dispatch

Post by cmb » Sun Oct 01, 2017 4:23 pm

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?
Christoph M. Becker – Plugins for CMSimple_XH

manu
Posts: 1085
Joined: Wed Jun 04, 2008 12:05 pm
Location: St. Gallen - Schweiz
Contact:

Re: Remove globals for core back-end dispatch

Post by manu » Mon Oct 02, 2017 11:21 am

Just go for it. A BC break might be easily recognized & fixed.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Remove globals for core back-end dispatch

Post by cmb » Mon Nov 27, 2017 11:09 pm

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.
Christoph M. Becker – Plugins for CMSimple_XH

Tata
Posts: 3586
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: Remove globals for core back-end dispatch

Post by Tata » Tue Nov 28, 2017 8:01 am

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...)}
} 
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Remove globals for core back-end dispatch

Post by cmb » Tue Nov 28, 2017 11:56 am

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.
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply