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 are the static keywords and class constants of OO 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 shows you the "PHP OO static keywords and class constants are what", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "PHP OO static keywords and class constants what are" this article.

Have nothing to do and casually look for some PHP information about OO, access control modifiers, self,parent,const,static keywords, arrow operators (also called in the book. That is, "- >"), the range parsing operator (double colon "::"), but I think this is the same as many OO in the C # language, but it's easy to understand, but it's good to take a look at the OO ideas in PHP.

Declare members and methods of a static class so that it does not require an instance of the class. The declaration of a static member cannot be accessed through an instance of a class object (although a static method can).

The static declaration must follow the visibility declaration. For compatibility with PHP 4, if no visibility is declared, then members and methods are deemed to have been declared as public.

Because static methods can call non-object instances, the pseudo variable $this cannot be used in methods that are declared static.

In fact, the form of the static method call is determined at compile time. When using a class name that must be declared, the method is fully identified and no inheritance rules are applied. This method is fully confirmed when you use a class name that must be declared, and there are no rules for inheritance.

If self has been declared, then self is interpreted by the class to which it currently belongs. Nor does it apply to inheritance rules. Static properties cannot be passed through the arrow operator->. Access to non-static methods, which produces an E_STRICT-level warning.

The copy code is as follows:

The copy code is as follows:

/ / static method instance (Static method example)

You can define a constant in each base class to keep it unchanged. Constants are different from ordinary variables when you don't use the $symbol to declare or use it. Like static members, constant values cannot be accessed through an instance of an object (instead, use $object::constant). A constant value must be a constant expression, not a variable, a member of a class, a mathematical expression, or the result of a function call.

The copy code is as follows:

These are all the contents of the article "what are the static keywords and class constants of OO 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