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

What does var mean in php?

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

Share

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

Editor to share with you what var means in php, I believe most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

Var means variable variable in php; in PHP, the class attribute must be defined as one of public, protected, and private, and if defined in var, it is considered public.

This article operating environment: Windows7 system, PHP7.1 version, DELL G3 computer

What does var mean in php?

The name of the defined string variable

Var means variable variable.

Usage of var keyword in php

Many friends say that it doesn't matter whether you use var or not to define variables in php, but it's not.

Look at the example, if I use var like this:

Var $axi123; echo $a; / / then the program will prompt for a syntax error, so you need to remove the variable definition var. Directly $axi123; echo $a; / / so you won't get an error. Php is a weakly typed language, so it's okay not to declare a type.

When will var be available? please see:

Class Test {var $astat123 obj=new Test / access control. The var is not normal if it is not used. Of course, you can use keywords such as public protected to declare the attribute of the member variable} $obj=new Test (); echo $obj- > a; / / print the result: 123

If you replace var with public, it's all right.

But at this time you remove var from the class and there are no access modifiers, which will indicate a syntax error.

In fact, after testing, I think that var is an alias for public, is used to define public properties in the class, but the history problem, now do not use var. Later, I checked the official website of php, and it was so.

Php's official explanation:

The class attribute must be defined as one of public, protected, and private. If defined in var, it is considered public.

Note: for compatibility reasons, the method of defining variables using the var keyword in PHP 4 is still valid in PHP 5 (just as an alias for the public keyword). In versions prior to PHP 5.1.3, this syntax produced an E_STRICT warning

The above is all the content of the article "what does var mean in php?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, 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.

Share To

Development

Wechat

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

12
Report