<?php
$z = 'z';
function ff()
{
global $z;
var_dump($z);
$z = 'not z';
var_dump($z);
}
var_dump($z);
ff();
var_dump($z);
?>.../modx/core/cache/includes/elements/modsnippet/47.include.cache.php:10:string 'z' (length=1)
.../modx/core/cache/includes/elements/modsnippet/47.include.cache.php:6:null
.../modx/core/cache/includes/elements/modsnippet/47.include.cache.php:8:string 'not z' (length=5)
.../modx/core/cache/includes/elements/modsnippet/47.include.cache.php:12:string 'z' (length=1)
This question has been answered by tester3. See the first response.
<?php
global $z; // <- Added an outer 'global'
$z = 'z';
function ff()
{
global $z;
var_dump($z);
$z = 'not z';
var_dump($z);
}
var_dump($z);
ff();
var_dump($z);
?>
.../modx/core/cache/includes/elements/modsnippet/47.include.cache.php:11:string 'z' (length=1)
.../modx/core/cache/includes/elements/modsnippet/47.include.cache.php:7:string 'z' (length=1)
.../modx/core/cache/includes/elements/modsnippet/47.include.cache.php:9:string 'not z' (length=5)
.../modx/core/cache/includes/elements/modsnippet/47.include.cache.php:13:string 'not z' (length=5)
I don't know what causes it, but I've had a number of occasions where global inside a snippet didn't work. I always pass $modx as an argument, which also cuts down the chance of collisions.What do you mean? How does the $modx argument help? Is there any way to use "local" "global" variables (excuse me for this name
) from it? Something like $modx->getGloablVariable('xyz') ?