Get the App
SLTechnology News&Howtos  ›  Database  › 

What is the difference between newstatic and newself in PHP

Shulou Source: shulou.com Published: 2022-05-31 21:37:47 10月01日 Update

This article shows you what is the difference between newstatic and newself in PHP. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

New self

Note that the line get_class (Son::getStatic ()) returns the class of Son, which can be summarized as follows:

Self returns the class where the keyword new in new self resides, as in this example:

Public static function getSelf () {return new self (); / / the new keyword is here in Father}

Always return Father.

New static

Static is a little smarter on the basis of the above: static returns the class that executes new static (), for example, Son returns Son for get_class (Son::getStatic ()), and Father returns Father for get_class (Father::getStatic ()).

In the absence of inheritance, new self and new static can be considered to return the same result.

The above is what is the difference between newstatic and newself in PHP. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Keywords keywords content skills knowledge same concise smart concise line example foundation that is situation location article more article result industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Microsoft Docker NVidia MariaDB