Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of variable types and scope in PHP

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "PHP variable types and scope detailed explanation", in daily operation, I believe many people in PHP variable types and scope detailed explanation problems have doubts, Xiaobian consulted all kinds of information, sorted out simple and easy to use operation methods, hope to answer "PHP variable types and scope detailed explanation" doubts helpful! Next, please follow the small series to learn together!

The scope of variables in PHP can be divided into: super global (special type of global variable, directly used in local scope), global, local, static (special type of local variable)

In PHP, global variables are actually static global variables. If you don't explicitly release them by unset, global variables will not be released until the script runs out.

Local static variable refinement can be local static function variables (static variables declared in functions), local static member variables (static attributes declared in classes, shared by all class instances)

Local static variables are automatically released only at the end of the script run

Hyperglobal variables: can be accessed from any scope of a script, these are built-in PHP

The copy code is as follows:

$GLOBALS

$_SERVER

$_GET

$_POST

$_FILES

$_SESSION(persistent storage)

$_COOKIE(persistent storage)

$_REQUEST

$_ENV

Global variables: declared variables are not inside class,function,if and other language structures. If you want to use them inside class,function,if and other languages, you need to use the keyword global or super-global variable $GLOBALS.

static variable: a variable declared with the keyword static in function, the value of the static variable is retained until the end of the script

Local variables: variables declared inside class, function, if/while/for statements

1.global keywords and $GLOBALS examples

The copy code is as follows:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report