If this is your first visit, check our documentation. To post, register or login.
Forums / Contribution-Writing Guidelines / Accessing global variables

Accessing global variables

Started by torvista on 11 Jun 2019, 11:38 AM · Views: 13,056

Results 1 to 3 of 3
11 Jun 2019, 11:38 AM
#1
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,880
Plugin Contributions:
7

Accessing global variables

When making my hacklets, I use Superglobals to tell me what variables are already available on that page by default so I don't reinvent the wheel.
I have an issue in 156 with not being able to access what I could in 1.55, at the same point.

Consider this code/try this (I used it in admin root).

<?php //test_globals.php //define('DEBUG_AUTOLOAD',true); require('includes/application_top.php'); echo 'BEFORE HTML<pre>$languages:'; print_r($languages);echo '</pre>'; echo '<pre>$languages_array:';print_r($languages_array);echo '</pre>'; echo '$languages_selected='.$languages_selected.'<br>'; ?> <!doctype html> <html lang="en"> <head> <title>Test Globals</title> <link rel="stylesheet" href="includes/stylesheet.css"> <?php echo 'HEAD<pre>$languages:'; print_r($languages);echo '</pre>'; echo '<pre>$languages_array:';print_r($languages_array);echo '</pre>'; echo '$languages_selected='.$languages_selected.'<br>'; ?> </head> <body onload="init()"> <?php require(DIR_WS_INCLUDES . 'header.php'); ?> Hello World <?php echo 'BODY<pre>$languages:'; print_r($languages);echo '</pre>'; echo '<pre>$languages_array:'; print_r($languages_array);echo '</pre>'; echo '$languages_selected='.$languages_selected.'<br>'; ?> <div class="footer-area"> <?php require(DIR_WS_INCLUDES . 'footer.php'); ?> </div> </body> </html> <?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

In 1.55 I get
Before HTML (ie where you would normally do php stuff)
$languages - available
$languages_array - not set
$languages_selected - not set

HEAD:
$languages - available
$languages_array - not set
$languages_selected - not set

BODY:
$languages - available
$languages_array - available
$languages_selected - available

In 1.56 I get
Before HTML:
$languages - not set
$languages_array - not set
$languages_selected - not set

HEAD:
$languages - not set
$languages_array - not set
$languages_selected - not set

BODY:
$languages - available
$languages_array - available
$languages_selected - available

The init_languages in 1.56 is a bit later than 1.5, I moved it earlier as much as possible (without breaking anything), but no change.

So, if "things have been tightened up in 1.56", the question is, what is one supposed to do to get at these variables now?

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

12 Jun 2019, 7:30 AM
#3
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,880
Plugin Contributions:
7

Re: Accessing global variables

...you didn't read my post twice....
all three appear in the Superglobals list...but they are not all available as expected, WHEN they are expected.

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...