Home  >  Article  >  Backend Development  >  Do you need to declare variables in php?

Do you need to declare variables in php?

silencement
silencementOriginal
2019-09-25 10:40:554313browse

Do you need to declare variables in php?

Because PHP is a weakly typed language, it can be used without declaring variable types.

$ is just syntax sugar, indicating that what follows is a variable. .

If it is explained in terms of memory space allocation

When a weakly typed variable allocates memory space, this memory space can store any type of variable. When using it, you need to search all memory areas,

and strong type is allocated in the specified memory according to the variable type, and the type cannot be converted directly. When using it, go directly to the area of ​​that type to find the value.

So generally changing the variable type in a weakly typed language can be modified directly. . However, strongly typed languages ​​cannot be modified directly, so the concept of pointers in strongly typed languages ​​is particularly important. We do not directly use the data in memory. We create a reference variable (pointer). If we want to modify it, we can directly Just modify the memory address pointed by the pointer.

The above is the detailed content of Do you need to declare variables in php?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn