Get the App
SLTechnology News&Howtos  ›  Development  › 

What does php static mean?

Shulou Source: shulou.com Published: 2022-06-02 09:14:37 10月03日 Update

This article mainly introduces what php static means. It is very detailed and has certain reference value. Friends who are interested must finish reading it.

Static is a built-in keyword in php, and we can use the static keyword to define static methods and properties, as well as static variables and later static bindings.

This article operating environment: windows7 system, PHP7.4 version, DELL G3 computer

Static is a built-in keyword for PHP.

Static (static) keywords

Tips

This page explains using the static keyword to define static methods and properties. Static can also be used to define static variables and later static bindings. See the above page for the use of static in it.

If a class property or method is declared static, it can be accessed directly without instantiating the class. Can be accessed statically in an instantiated class object.

Static method

Because static methods do not need to be called through an object, the pseudo variable $this is not available in static methods.

Warning

Calling a non-static method statically throws an Error.

Prior to PHP 8.0.0, the use of calling a non-static method statically had been deprecated and resulted in an E_DEPRECATED-level warning.

Example # 1 example of static method

Static attribute

Static properties are accessed using the range resolution operator (::) and cannot be accessed through the object operator (- >).

It is possible to reference a class through a variable, but the value of this variable cannot be a reserved word (for example, self,parent and static)

Example # 2 example of static attributes

The output of the above routine in PHP 8 is similar to:

Foofoo

Notice: Accessing static property Foo::$my_static as non static in/ in/V0Rvv on line 23

Warning: Undefined property: Foo::$my_static in/ in/V0Rvv on line 23

Foofoofoofoo

The above is all the contents of this article "what does php static mean?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Static method property key variable keyword example object meaning content instance operator method article feasibility value keyword interest buddy buddy Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Tech Info Apple Shulou Information vpn