Classes in PHP

Source: Internet
Author: User
I feel that the most difficult concept to understand since the application of PHP is the PHP class. I have no experience with other database engines except I am learning some basic MySQL knowledge. Previously I had no experience with OOP object-oriented programming. for me, OOP is the most difficult concept to understand since I applied PHP. I have no experience with other database engines except I am learning some basic MySQL knowledge. Previously, I had no experience with OOP object-oriented programming. OOP is also a novel thing for me, but through understanding its principles and why it is so powerful, it makes me certain that I understand that if any program is implemented using OOP, it will undoubtedly get a strong program. but for me, if I just think that I understand the mechanism, without exploiting this knowledge to programming practices, OOP will always stay at the level of paper discussion. So a few days ago, when I used conventional functions to implement some functions, I tried to use objects for implementation. I did invent it, which made my work simpler! So I wrote these experiences and hoped they could help people like me.

Class arguments are the aggregation of some variables (member variables in the OOP concept, note by the translator) and some functions that control the processing of these variables (member functions in the OOP concept. It provides a method for thinking about titles in the form of real life in the program. In other words, it describes an object. On the contrary, an object or instance is the real implementation of this class. For example, we want to describe a bicycle: a suitable bicycle class should contain the following variables: $ pedals (pedal), $ chain (chain), $ front wheel (front wheel ), $ rear wheel, $ brakes, and $ handl_bars ). You can refer to the control of a bicycle in real life to implement your script. For example, you can pass a $ Braking_Force to the Accelerate () function, and use this variable to use other variables of your defined instance, such as $ front_wheel, $ rear_wheel, you can also return the result of the control to achieve the corresponding control.

It looks beautiful, but can't these functions and variables be implemented by convention? Well, if you only have one bicycle instance in your program and define a category for it, it doesn't really mean much, but what if you need many bicycle instances? However, the variable transfer flow in your program becomes quite complex. you must always ensure that the variables specified by each bicycle instance are passed to different functions accurately. However, the application object greatly reduces the number of variables you pass, because the processing functions in the object (so-called method, translator .) The scope of active identification is limited to this object, so the objects it can hold are limited to the object category. In addition, the definition of objects can be easily included in different scripts for only use (when reusable) it also ensures that each bicycle works in the same way in different scripts.

Let's create an actual class. this class is used on almost every page of my website. maybe you will find something worth your reference.

I don't know what your situation is, but for me, when I write a dynamic web page, what I hate most is to interrupt thinking about the program process from time to time, instead, let's look at the appropriate representation of HTML. The result of this is to make the pages that I finally made less attractive, because I don't have so much energy to take into account the font, font size, background, and text colors. The solution is to implement text pattern through the PHP class, so as to customize HTML output attributes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.