Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

PHP Scope of Variables

I just had a broad question that wasn't clearly answered online. Does a variable have a scope and if so does it only apply when it is in a function or does it also extend into everything that has brackets?
(Apr 4, 2019 04:25 PM)Jack Drake Wrote:  I just had a broad question that wasn't clearly answered online. Does a variable have a scope and if so does it only apply when it is in a function or does it also extend into everything that has brackets?

clear online answer here.

Local variables (local scope)
- A local scope is a restricted boundary of a variable within which code block it is declared.

Global variables (special global scope)
- As its name, the global scope provides widespread access to the variable declared in this scope.

Static variables (local scope)
- A static variable is a variable with local scope. A static variable does not lose its value when the program execution goes past the scope boundary. But it can be accessed only within that boundary.

Function parameters (local scope)
- Function parameters (arguments) are local variables defined within the local scope of the function on which it is used as the argument.

SO, for your more specific question, if you declare a variable in a function, it's a local variable. It can only be modified/referenced to in that function. If this is ur desire, this is where you start passing in variables to your functions.
[Image: wKo4TU0.gif]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Javascript]  by SIM-1517830Feb 3, 2021 02:48 PM 17 448 Feb 3, 2021 02:48 PM
Last Post: SIM-1517830
[PHP] by AussieMay 3, 2020 06:00 AM 2 142 May 3, 2020 06:00 AM
Last Post: Aussie
[PHP] by EffexionDec 16, 2018 06:32 PM 13 249 Dec 16, 2018 06:32 PM
Last Post: gigajew