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

How to use the $this-> method in php

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

Share

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

This article mainly explains the "php $this- > method how to use", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "php $this- > method how to use" it!

In PHP, "$this- >" indicates the use of the class's properties or methods within the class itself; "$this" represents the instantiated concrete object, and "- >" is the insert dereference operator and the method that invokes the subroutine passed by the reference.

This article operating environment: Windows10 system, PHP7.1 version, Dell G3 computer.

What is the $this- > method in php

In php, we usually declare a class first, and then use this class to instantiate the object! The meaning of $this is to represent the concrete object after instantiation! $this- > means to use the class's properties or methods within the class itself.' The-> 'symbol is the insert dereference operator (infix dereference operator). In other words, it is a method that invokes a subroutine that passes parameters by reference (and, of course, other functions). As we mentioned above, when calling the function of PHP, most of the parameters are passed by reference.

For example, let's declare a User class! It contains only one attribute $name

Now, let's add a method to the User class. Use the getName () method to output the value of the $name attribute.

Two User objects are created above. They are $user1 and $user2 respectively.

When $user1- > getName () is called. The code in the User class above is echo $this- > name; it is equivalent to echo $user1- > name

Thank you for your reading, the above is the content of "how to use the $this- > method in php". After the study of this article, I believe you have a deeper understanding of how to use the $this- > method in php, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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