In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use class in php", the explanation content in the article is simple and clear, easy to learn and understand, please follow the idea of Xiaobian slowly in-depth, together to study and learn "how to use class in php"!
class in php is the keyword used to declare a class. The syntax for defining a class in php is usually in the form of "class phpClass {var $var1;function myfunc ($arg1, $arg2) {...}}." "。
Operating environment: Windows 7, PHP 7.4, DELL G3
What does class mean in PHP?
The class in php is the keyword used to declare a class.
PHP class definitions
PHP defines classes in the following syntax:
The analysis is as follows:
Classes are defined using the class keyword followed by the class name.
Variables and methods can be defined within a pair of braces ({}) after the class name.
The variables of a class are declared using var, and variables can also be initialized.
Function definitions are similar to those of PHP functions, but functions can only be accessed through the class and the objects it instantiates.
examples
The variable $this represents its own object.
PHP_EOL is a newline.
Creating objects in PHP
After a class is created, we can instantiate objects of that class using the new operator:
$runoob = new Site;$taobao = new Site;$google = new Site;
In the above code, we created three objects, each of which is independent. Next, let's see how to access member methods and member variables.
invoke member method
After instantiating an object, we can use that object to call member methods that can only operate on member variables of that object:
//Call member function to set title and URL$runoob->setTitle( "rookie tutorial" );$taobao->setTitle( "Taobao" );$google->setTitle( "Google Search" );$runoob-> setUrl ('www.example.com');$taobao->setUrl www.taobao.com;$google->setUrl www.google.com;/Call member function to get title and URL$runoob->getTitle();$google-> getTitle ();$runoob->getUrl();$taobao->getUrl ();$google->getUrl(); www.runoob.com
The complete code is as follows:
examples
Executing the above code, the output is:
Rookie tutorial Taobao Google search www.runoob.comwww.taobao.comwww.google.com Thank you for reading, the above is the "php class how to use" content, after learning this article, I believe everyone on php class how to use this problem has a deeper experience, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.