ElkArte Community

Elk Development => Feature Discussion => Exterminated Features => Topic started by: Nao on December 12, 2013, 06:23:17 pm

Title: Unused globals
Post by: Nao on December 12, 2013, 06:23:17 pm
Well, as you know it's a bit of a hobby for me these days...
http://wedge.org/pub/off/8300/a-short-script-to-remove-unused-useless-globals-in-php/

I've been updating my script to add more features (most notably looking for undeclared globals). It gave me a few results for Wedge (which I subsequently fixed), and then I tried it on Elk, which allowed me to fix more bugs (e.g. find less false positives.)

My current results for Elk are, as follows:
- 4 "duplicate globals" errors, each in a different file.
- 43 "unneeded globals" errors, 80%+ being in install.php, upgrade.php and Stats.template.php, with the rest evenly divided between other files.

Do you want me to 'fix' that for you guys..? Or would you rather check them manually, and then fix them?

Bugger... Had something else to say, but I totally forgot! :-/
Title: Re: Unused globals
Post by: Nao on December 12, 2013, 07:01:22 pm
Ah yes, I remember now... Do you guys have any new global variables that are used in Elk but not in SMF?
So that I can add them to the list of 'undeclared globals'. (I have to explicitly list them.)
Title: Re: Unused globals
Post by: emanuele on December 12, 2013, 07:41:39 pm
Quote from: Nao – - 43 "unneeded globals" errors, 80%+ being in [...] and Stats.template.php
/me is guilty!

Darn, that's what I forgot to do after reworking it... :-[

Quote from: Nao – Do you want me to 'fix' that for you guys..? Or would you rather check them manually, and then fix them?
I'm a bit afraid of install and upgrade, the two are not always so straightforward when it comes to variables... I think...

Quote from: Nao – Bugger... Had something else to say, but I totally forgot! :-/
Welcome to my world! :D

Quote from: Nao – Do you guys have any new global variables that are used in Elk but not in SMF?
Nope, only removed as much as possible (and I think there is still one that could be safely removed), not added any new... I hope. :P
Title: Re: Unused globals
Post by: Nao on December 13, 2013, 06:44:17 am
install and upgrade are straightforward when it comes to unneeded globals. Plus, I have my false-positive detection code.
The latest script version has an option to remove false positives from the list, so here's a full list of 'sure fire' errors it found for ElkArte. Feel free to fix them manually. Or, if you don't want to, I can ask the script to do it for me, and I'll do a pull request.

Unused global in /install/install.php:132 (initialize_inputs) -- $databases
Unused global in /install/install.php:132 (initialize_inputs) -- $incontext
Unused global in /install/install.php:301 (installExit) -- $txt
Unused global in /install/install.php:2016 (template_install_above) -- $oursite
Unused global in /install/install.php:2132 (template_welcome_message) -- $installurl
Unused global in /install/install.php:2280 (template_database_settings) -- $installurl
Unused global in /install/install.php:2375 (template_forum_settings) -- $installurl
Unused global in /install/install.php:2421 (template_populate_database) -- $installurl
Unused global in /install/install.php:2464 (template_admin_account) -- $installurl
Unused global in /install/upgrade.php:507 (initialize_inputs) -- $upcontext
Unused global in /install/upgrade.php:507 (initialize_inputs) -- $db_type
Unused global in /install/upgrade.php:856 (action_upgradeOptions) -- $db_prefix
Unused global in /install/upgrade.php:857 (action_upgradeOptions) -- $boardurl
Unused global in /install/upgrade.php:857 (action_upgradeOptions) -- $mmessage
Unused global in /install/upgrade.php:1078 (action_databaseChanges) -- $language
Unused global in /install/upgrade.php:1078 (action_databaseChanges) -- $boardurl
Unused global in /install/upgrade.php:1410 (convertSettingstoOptions) -- $db_prefix
Unused global in /install/upgrade.php:1538 (db_version_check) -- $db_connection
Unused global in /install/upgrade.php:1551 (getMemberGroups) -- $db_prefix
Unused global in /install/upgrade.php:1608 (parse_sql) -- $db_connection
Unused global in /install/upgrade.php:2149 (textfield_alter) -- $databases
Unused global in /install/upgrade.php:2149 (textfield_alter) -- $db_type
Unused global in /install/upgrade.php:2304 (nextSubstep) -- $file_steps
Unused global in /install/upgrade.php:2304 (nextSubstep) -- $modSettings
Unused global in /install.php:158 (initialize_inputs) -- $databases
Unused global in /install.php:158 (initialize_inputs) -- $incontext
Unused global in /install.php:347 (installExit) -- $txt
Unused global in /install.php:2015 (template_install_above) -- $oursite
Unused global in /install.php:2133 (template_welcome_message) -- $installurl
Unused global in /install.php:2281 (template_database_settings) -- $installurl
Unused global in /install.php:2401 (template_forum_settings) -- $installurl
Unused global in /install.php:2447 (template_populate_database) -- $installurl
Unused global in /install.php:2490 (template_admin_account) -- $installurl

Found duplicate globals in /sources/admin/ManageBoards.controller.php (action_main) -- $txt, $context, $cat_tree, $boards, $boardList, $scripturl, $txt

Found duplicate globals in /sources/admin/ManageSmileys.controller.php (action_editsmiley) -- $modSettings, $context, $txt, $scripturl, $modSettings

Found duplicate globals in /sources/admin/PackageServers.controller.php (action_browse) -- $txt, $context, $scripturl, $forum_version, $context

Found duplicate globals in /sources/controllers/Notify.controller.php (action_notify) -- $topic, $scripturl, $txt, $topic, $user_info, $context

Unused global in /sources/controllers/Stats.controller.php:127 (loadGeneralStatistics) -- $txt
Unused global in /sources/ext/simple_html_dom.php:865 (get_display_size) -- $debug_object
Unused global in /sources/ext/simple_html_dom.php:1045 (load) -- $debug_object
Unused global in /themes/default/BoardIndex.template.php:31 (template_boards_list) -- $settings
Unused global in /themes/default/BoardIndex.template.php:31 (template_boards_list) -- $scripturl
Unused global in /themes/default/Display.template.php:99 (template_messages) -- $modSettings
Unused global in /themes/default/MessageIndex.template.php:31 (template_display_child_boards_above) -- $scripturl
Unused global in /themes/default/MessageIndex.template.php:31 (template_display_child_boards_above) -- $settings
Unused global in /themes/default/ModerationCenter.template.php:486 (template_user_watch_post_callback) -- $delete_button
Unused global in /themes/default/Stats.template.php:23 (template_statistics) -- $settings
Unused global in /themes/default/Stats.template.php:23 (template_statistics) -- $txt
Unused global in /themes/default/Stats.template.php:23 (template_statistics) -- $scripturl
Unused global in /themes/default/Stats.template.php:23 (template_statistics) -- $modSettings
Unused global in /themes/default/Stats.template.php:45 (template_general_statistics) -- $scripturl
Unused global in /themes/default/Stats.template.php:45 (template_general_statistics) -- $modSettings
Unused global in /themes/default/Stats.template.php:108 (template_top_statistics) -- $settings
Unused global in /themes/default/Stats.template.php:108 (template_top_statistics) -- $scripturl
Unused global in /themes/default/Stats.template.php:108 (template_top_statistics) -- $modSettings
Unused global in /themes/default/Stats.template.php:233 (template_forum_history) -- $scripturl

PS: quick edit is broken, and quick reply has a 100px wide window for typing text, or something... I have to maximize my window again to ensure it triggers a larger width. Nasty bug...! Also, it doesn't focus when I click the textarea; only when I click near the beginning. That's not a textarea right, it's a wysiwyg div..? But wysiwyg is disabled on my page, so... That's odd.
Title: Re: Unused globals
Post by: emanuele on January 04, 2014, 11:04:46 am
Quote from: Nao – install and upgrade are straightforward when it comes to unneeded globals. Plus, I have my false-positive detection code.
Oook.
I'm always a bit worried about that piece of code because it's not always so easy to follow for me... :-[
Mind you, I still have to understand where $boardurl is used in action_forumSettings... ???

Quote from: Nao – The latest script version has an option to remove false positives from the list, so here's a full list of 'sure fire' errors it found for ElkArte. Feel free to fix them manually. Or, if you don't want to, I can ask the script to do it for me, and I'll do a pull request.
I suppose we can try! :P
@Spuds ?
Title: Re: Unused globals
Post by: Spuds on January 04, 2014, 03:57:29 pm
I know I did some of these based on this post (not the install or upgrade ones though).  I'll take a look to see if we got the rest of these cleaned up  ;D
Title: Re: Unused globals
Post by: Nao on January 04, 2014, 04:34:27 pm
Current versions of my script are geared towards php 5.3 lambda functions so I was pretty much forced to give up on auto fixing because of an increased level of complexity. Feel free to use previous revisions of it, though! Their only drawback is that they don't do create_function and I did find a few unused globals in these, after converting them to lambdas.