PHP object-oriented programming = inheritance

xiaoxiao2021-03-06  57

Overview of PHP-oriented programming is a method of usual use of project development. This section we will show how object-oriented programming (OOP, Object Oriented Programming) is performed in PHP, and explain how to reduce encoding and increase quality by using some OOP concepts and PHP skills. Before applying the PHP class, please check the relevant object-oriented programming books, understand the basic knowledge of object-oriented and classes. How to create an instance object of class and classes? In the PHP, you can complete the package through class, let's take a simple example: name when accessing the class member variables in the method. , Such as $ this-> setValue function setValue ($ V) {$ this-> value = $ v;} function getValue () {return $ this-> value;}} // Create an object with "new" operator $ Obj = new classname; $ OBJ-> SetValue ("Hello, PHP World!"); $ obj-> getValue ();?> Inherits the "extend" keyword. For example: message = $ msg;} function getMessage () {return $ this-> message;}}> "HelloPHPWorld"? The object of class now has all the data members and methods of the ClassName, and there are also their own data members and methods. We can use: $ obj2 = new hellophpworld; $ obj2-> setValue ("i love world!"); $ Obj2-> setmessage ("i love php!"); PHP now does not support multiple inheritance, so you can't be from two Or two or more class are derived from new classes.

转载请注明原文地址:https://www.9cbs.com/read-113586.html

New Post(0)