[OOP]: Object-oriented programming: basic syntax

Posted on 2015-08-18 10:24:11

Advanced PHP - first article we learn object-oriented programming is what ?. Following this article we will explore further the basic syntax of object-oriented programming ...
Advanced PHP - first article we learn object-oriented programming is what? . Following this article we will explore further the basic syntax of PHP object-oriented programming. 1. Declare the class and instance of the class in PHP As we all know, a class including attribute types and methods. In PHP5, we declare a class with the following syntax. After creating the class, you can create and store them in a variable using the new keyword. To view the contents of the class, you use the function var_dump () 2. Define the properties of the Class To add data to a class, we use attribute , or a certain individual variables. They work similar to regular variables, only one thing is they're linked with object and therefore to be able to access and use the object we have adopted or otherwise use object. To add a property to MyClass, you add the following code to your script Keywords public determine the scope of the attribute. Next, the name of the property complies with the standard syntax for the variable name, and a value was assigned to it (although properties of the class do not necessarily have the original value). But we'll find out about them in the following sections. To read this attribute and outputs them to the browser, we will have to reference them through the object. If we do not declare the object, the program will not be able to identify any object attribute belongs (for understanding one simple way is to represent the class object). Use the arrow (->) is an Object Oriented structure, so an object can access the contents of the attributes and methods of class. 3. Definition of Class Method Modes are separate functions of class. The individual action, but an object executes, it is defined within the class as methods. For example, to create the method is capable of setting and returns the value of attribute $ prop1 , we add the following code. Note: User Objects allows the self-referential object itself (referenced within the class) by using the variable $ this.When working within one method, use $ this in the same way you use external object class name. To use these methods, calling them similar use common functions, but we must pass the object to the reference to them. Echo tuMyClass attributes, change its value, and echo it again to see the change. Power of Object Oriented more and more visible when we use the same class for many cases. As you can see, User Audience hold objects as separate entities , thereby making the separation of code into different small parts that retain a certain relationship between them easily.