/    Sign up×
Community /Pin to ProfileBookmark

Global Variables and Super Globals Question

Folks,

Is my following comment correct or mistaken ?
$GLOBALS[‘z’] = $GLOBALS[‘x’] + $GLOBALS[‘y’]; **//A new “Global Variable” ‘$z’ is created inside the function.**

Context:

[code]
$x = 1; //’Global Variable’ as outside function. It now exists in “Super Global” Variable array as: $GLOBALS[‘x’].
$y = 2; //’Global Variable’ as outside function. It now exists in “Super Global” Variable array as: $GLOBALS[‘y’].

function addition()
{
$GLOBALS[‘z’] = $GLOBALS[‘x’] + $GLOBALS[‘y’]; //A new “Global Variable” ‘$z’ is created inside the function.
}

addition();

echo $z; //Since ‘$z’ is present within the $GLOBALS[index] array. It is accessible outside the function.

[/code]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 06.2021 — See my reply to your other thread, and just say "NO!" to using global or $GLOBALS within functions.
Copy linkTweet thisAlerts:
@developer_webauthorApr 06.2021 — @NogDog#1629995

Ok. I understand you don't like using $GLOBALS inside functions. And you prefer export().

But I still need to know if my above comment (in bold) is incorrect or correct. That is all.

Only answer after checking again my full code above.
Copy linkTweet thisAlerts:
@NogDogApr 06.2021 — Again, see my reply to your other thread. Spreading a discussion across multiple forum threads is a wast of everybody's time here.
Copy linkTweet thisAlerts:
@NogDogApr 06.2021 — {"locked":true}
×

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...