Why do php variables not need to be specifically declared?

Source: Internet
Author: User
The problem is as follows: php does not need to declare variables. Does the system know what variables are and allocate space to them based on $? Does it need to declare variables because php is a weak language? The problem is as follows: php does not need to declare variables. Does the system know what variables are and allocate space to them based on $? Does it need to declare variables because php is a weak language?

Reply content:

The problem is as follows: php does not need to declare variables. Does the system know what variables are and allocate space to them based on $? Does it need to declare variables because php is a weak language?

The underlying C of php is stored by a consortium union, which contains various variable types. php uses the long type to store integers and hashtable Hasse tables to store arrays, because union can store various variables, and the interpreter will automatically determine the variable type, php does not need to declare the variable type, weak type

Yes, because php is a weak type language, you can use it without declaring the variable type ..

$ Is just a syntactic sugar, indicating that it is followed by a variable ..

If the explanation is based on the memory space allocation

  • When allocating memory space for weak variables, this memory space can store any type of variables. You need to find all memory areas when using

  • The strong type is allocated to the specified memory according to the variable type, and the type cannot be converted directly. You can find this value in this type of area when using it.

Therefore, you can directly modify the variable type in a weak language .. However, a strong language cannot be directly modified. Therefore, the pointer concept of a strong language is particularly important. we do not directly use data in the memory. we create a reference variable (pointer ), if you want to modify the memory address pointed to by the pointer, you can.

.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.