In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
What are the differences between js global variables and php global variables? the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what is the difference between js global variables and php global variables" can help you solve your doubts.
The difference between js global variables and php global variables: PHP calls global variables in functions using the global keyword, which is used to import global variables, while calling global variables in js does not need to use keywords.
This article operating environment: Windows10 system, PHP7.1 version, Dell G3 computer.
What is the difference between js global variables and php global variables
PHP global keyword
The global keyword is used to access global variables within a function.
To do this, use the global keyword before the variable (inside the function):
Example
Js global variable
The declaration of global variables in JS is mainly divided into explicit declaration or implicit declaration, which are described below.
Mode 1 of the declaration:
Use var (keyword) + variable name (identifier) to declare outside function, that is, global variables, otherwise local variables are declared in function. This method is explicitly declared as follows:
Var test = 5; / / global variable function a () {var cc=3; / / local variable alert (test);} function b () {alert (test);}
Mode 2 of the declaration:
Instead of using var, directly assign a value to the identifier test, which implicitly declares the global variable test. Even if the statement is within a function, the test becomes a global variable when the function is executed.
Test = 5 test / global variable function a () {aa=3; / / global variable alert (test);}
Advantages of js global variables:
The number of variables can be reduced and the time consumption caused by the data transmission of actual parameters and formal parameters can be reduced.
Disadvantages of js global variables:
(1) the global variable is stored in the static memory area, and the memory is allocated to it when the program starts to run, and the memory is released at the end of the program. Compared with the dynamic allocation and dynamic release of local variables, the lifetime is longer, so too many global variables will occupy more memory units.
(2) Global variables destroy the encapsulation performance of the function. The function is like a black box, which is generally input and output through function parameters and return values, and the internal realization of the function is relatively independent. However, if global variables are used in the function, then the statements in the function can bypass the function parameters and return values for access, which destroys the independence of the function and makes the function dependent on global variables. At the same time, the portability of the function is reduced.
(3) Global variables reduce the readability of the code of the function. Because multiple functions may use global variables, the value of global variables may change at any time when the function is executed, which is very disadvantageous to the error checking and debugging of the program.
Therefore, it is best not to use global variables if it is not a last resort.
Read here, this article "what is the difference between js global variables and php global variables" article has been introduced, want to master the knowledge of this article also need to do your own practice to understand, if you want to know more related articles, welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.