Deprecate initvar() in XH 1.7.0

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:

Deprecate initvar() in XH 1.7.0

Post by cmb » Thu Apr 06, 2017 2:08 pm

Hi everybody!

I don't think that using initvar() is a good idea. Often using a local variable or a property of an object is sufficient instead of introding a new global variable, and often it is best to clearly distinguish between "GET" and "POST" parameters. In any way, global variables should be best avoided, but if they are used, they should be at least clearly marked as such, instead of defining them via a function (which gets more easily overlooked and is harder to grep for).

Therefore, I suggest to deprecate initvar() in CMSimple_XH 1.7. The function is used by the core only in two places, where we could inline the function (possibly using a closure instead) to avoid the deprecation notice. It's not really great to tell plugin developers not to use a function, but to use it in the core behind the scenes, but I guess we can't go further for XH 1.7 for BC reasons.
Christoph M. Becker – Plugins for CMSimple_XH

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

Re: Deprecate initvar() in XH 1.7.0

Post by cmb » Thu Apr 06, 2017 2:22 pm

To clarify with regard to plugins which sometimes call `initvar('admin')` and `initvar('action')`: the latter is never needed, as $action is already initialized by the core since a very long time (actually much longer than CMSimple_XH 1.5.10). The former may still be necessary, although `initvar('admin')` is called inside `print_plugin_admin()` which is often called before `$admin` is used. However, some plugins may not call `print_plugin_main()`, so it appears to make sense to add 'admin' to the list of global variables which are initialized early by the core – I don't see any relevant BC issues with this.
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply