PHP mature _ PHP Tutorial

Source: Internet
Author: User
Tags php software
PHP is mature. As PHP is mature, it is time to quickly compile out-of-the-box scripting staff and understand the UML object-oriented developers to "reach an agreement. Few programming languages As PHP is mature, it is time to quickly compile out-of-the-box scripting staff and understand the UML object-oriented developers to "reach an agreement.

Few programming languages can be popularized as quickly as PHP. The widely publicized script language about DIY has changed the IT industry, and IT shows that success is not always from system planning and market research. However, the actual problem is how such success can be accepted by a large IT industry. Oracle and several other major participants are following the fact that the language is mature.

Until now, the success is just "appeared ". A growing number of fans have already gathered around PHP, just like a gifted prodigy. But since the child is growing and talking to adults on an equal footing, will early advocates adapt to this change?

Like most major open-source projects, PHP is a basic phenomenon in the process of becoming a mainstream technology. Will PHP disappoint those who make it reputation? Will IT meet the expectation of a huge IT industry?

Two programming cultures

The success of PHP attracted the attention of people of different backgrounds. Early advocates of Rasmus (if you can understand the slightly self-built tone that rarely appears in open-source circles) are used to fast out-of-the-box scripting, they now have to deal with developers who understand UML and object-oriented programming, who are determined to bring PHP together with other modern development tools. Both parties are familiar with Web development and have a strong culture. It is unwise to ignore either party.

In the early days of PHP, what aspects of Web development were known? what is it good at? what is it not good? It knows a lot about design. Its style may sometimes have problems, but it can be seen that it has HTML and CSS functions, and it does not have to be said that it is a more popular multi-information Internet application (RIA) technology. It is always so young, but often appears in PHP forums. The term "object-oriented" may have negative meanings for it. Its code is very concise, focusing on performance rather than maintainability.

Fill in HTML code with loose variables Therefore, the UML type is less attractive. It will consider the application architecture, class-level code reuse, teamwork, and source code management. It knows that a website with moderate complexity is also an application, and poorly designed applications will lead to delays in construction, annoying customers, or even losing their jobs.

At first glance, the latter seems to be more suitable for more and more environments, in which Web development will be increasingly driven by marketing strategies and economic factors. But should we regard the former as an endangered species? Maybe not. If we admit that Web is a medium that is very different from desktop systems-not to mention mainframes (do you still remember 3270 ?), A dominant development method is created in a large machine environment-we may come to the conclusion that, after all, we can learn from this method of success but relatively messy and effective.

Let's review the actual problems in order to overcome them before they may happen and review some practical work methods.

Bridge cultural gaps

Now PHP5 is about to bring object-oriented technology into the PHP world. Zend engine modification (ZE2) is introducing objects to the core of the language. Not only does the new language structure encourage the object programming style, but the implementation of the language is also adapting to other object-oriented environments. For example, objects are not replicated back and forth by default, but are processed by reference. New keywords (such as final or static) are introduced. they are only related to object concepts and are reserved for Java styles. other features (such as delegation) encourage the use of object design patterns. (We look forward to hearing you talk about "the original PHP4" in a few months ".) This profound change comes from the relentless revolutionary transfer to the current dominant programming model. Whether you like it or not, object methods will become popular because they have proved to be the most effective in providing complex applications, whether they are Web applications or not. This leaves us with no choice but to find imaginative ways to coordinate two cultures so that people with design ideas and those who understand the architecture can learn from each other.

To this end, you must develop (or change from another platform) a variety of methods to achieve language versatility while including it in a clear boundary. In this way, the "island" of programming creativity can exist in a robust architecture.

The obvious fact is that, despite the explosive growth in the number of php cms or application frameworks, there is no consensus on them. The common complaint is that no matter what your project is, the current system cannot complete the task. Most people begin to evaluate a number of systems, and often develop their own frameworks from scratch. Why?

In a desktop system, it seems that the operating system has completely solved the GUI design problem. On the contrary, Web is an important platform for original visual design. Websites carry the images and personalities of commercial companies and may increasingly affect their revenue. Visual Creativity and brand play a role together, so they must be promoted.

At the same time, flexible logic must be incorporated into applications to improve user experience as much as possible, users are more "dish" on the Web than they may be in desktop systems ".

This is a problem when the designer is constantly disappointed with the system designed by the programmer, and when the developer has to forcibly add the application code to the incomplete portal framework, this is also a problem. The most common outcome is an unsatisfactory compromise-a somewhat dull look that sacrifices a lot of availability to limit application complexity to a manageable level. (This phenomenon is not limited to PHP applications .)

To completely overcome these limitations, designers and object-oriented developers must find a way of collaboration that does not impede their work. The best way is to start by understanding how the team works.

From skill to industry

At this moment, we should not consider collaboration. let's observe their actual operations. Let's start from the historical order of PHP and first visit the store of an "enhanced html" user.

Transaction tools are similar to those of "pure html" users: some html editors provide various levels of comfort and project management features, it is also integrated with PHP, ASP, JavaScript, and secondary tools to some extent.

Let's take a closer look at the code. We will first notice that the websites generated using these different types of tools are very beautiful. Here we refer not only to technology, but also to talent. Given the constraints of abstract programming, Web designers are playing with positive and subtle emotional effects (similar to the effects created by smart decorators in real stores) it creates a visual environment that makes your website customers feel comfortable.

When we look at the code from the perspective of trained object-oriented programmers, things suddenly become bad. The code looks like it itself: it is a one-time, out-of-the-box job without any preparation for future development or simple maintenance. This is often the case.

So, what's wrong with this? Will it become a problem in the future, leading to the abandonment of some or whole websites and reconstruction from the beginning? Maybe not. After all, real store decoration is often removed and rebuilt on a regular basis. As a result, the cowboy-style PHP programming is enough for these window-style websites. This language is rich in a variety of techniques that help you achieve visual effects that attract the attention of visitors. This is obviously irrelevant to the object method.

This idea changes significantly once some application logic is needed. Do you need several forms to collect a small amount of marketing information about regular customers on your website? If you want this information to be pertinent, you 'd better add verification code. In this case, make sure that you can filter malicious scripts or SQL commands for intrusive attacks. By the way, since you are reading the OTN article, you must be familiar with the database (DB) problem. The information you want to collect will be stored in some database tables, and the SELECT statement in your PHP code will reflect this database structure. From now on, this website has been fixed in your business infrastructure-it is becoming a mature application.

We do not care about all of its hard-coded links, dangerous type conversion, and security vulnerabilities for the moment, and then access the latest PHP object-oriented application assembly line. For our artist-style Web designers, such a place may be unfamiliar or even unfriendly. Skills are not very important here. Web development has been industrialized. To accept this, you must be familiar with classes, inheritance, data abstraction, and a large number of code encapsulation tools.

Rules are required for team collaboration. The programming convention must be followed; the source files must be submitted to version management and source code management. Files are organized according to strict modular layers. Abandon the dangerous coding skills-especially the clever ones. The code must not only be readable, but also have good comments.

This may be annoying but effective. Now we are creating Web applications: intranets, commercial Web sites, e-markets, and various applications. defective designs may lead to shutdown. In short, we are overcoming complexity.

PHP object-oriented assembly line managers do not choose PHP because they love this language. They do this because it not only works as effectively as other proprietary languages, but also is free and has no additional conditions.

Where are we going?

So how will we use the industry-level methods provided by those trained in C ++ and Java to potentially supplement the expertise of the multi-functional languages used by early users?

PHP5 will shake many habits, so it may be too early. Some people will be forced to adopt a certain degree of object-oriented method, while others will eventually understand all the content of object-oriented and become its creditability. Some small environments may run as well as in the past and continue to flourish.

Let's try it out.

Now let's go deep into the basic technical level, learn how to develop simple habits, and how to find simple and effective solutions to help us prepare for the coming changes. A large number of very simple practices help to facilitate programming and make the application ready for expansion.

Naming conventions (habits of C ++ programmers) are the easiest way. If you have used a large number of code libraries (such as PEAR), it may be a good idea to use this convention as your own practice; otherwise, you should develop your own internal rules. Simplified Hungary annotations (named according to Charles Symonyi, the inventor of Hungary) can be widely used within the range allowed by loose types. You can also use underscores as the prefix of class members. Another useful habit is to append a special prefix (such as impl _) to a method (a class function) that is not used to call from outside the class _).

No matter what naming conventions you adopt, make your code as clear as possible. In this way, trained people may find programming errors in PHP on full screen, just because it looks problematic, just like a flaw in the portrait.

Another important aspect of naming conventions is to avoid name conflicts, making it possible to reuse code in a wide range. Experience tells us that programmers are not always very imaginative in naming programming objects. It is very likely that there are many Page classes, and it is not impossible to find that when you need to reuse two Page classes, they only have the same name but have different purposes. Lucky enough. In the long run, renaming will cause maintenance problems. You 'd better avoid this problem from the beginning. Generating a GUID will be too positive and ugly (for example, _ 16B280C5_EE70_11D1_9066_00C04FD9189D_Page !) It is contrary to the spirit of PHP.

A simple and conflicting method is to ensure the uniqueness of the internal class by associating several different aspects of the class to its name (for example, GalleryPage, to eliminate the possibility of conflicting classes beyond your control, you can use Java to prefix the reserved version of your domain name (com_mydomain_GalleryPage ).

Another habit that needs to be developed does not require you to spend anything, and it can save your work when unexpected changes to the scope of an application are inevitable, this is to encapsulate the most common basic statements in a separate channel. For example, in addition to debugging code, there should be only one "response" statement in the entire application, which should be in a function (or a separate class method. If the output needs to be preprocessed or redirected in a new environment, you know where to write the required lines of code without worrying about searching and editing a large number of files.

Error handling does not have to be as strict as in C ++-in C ++, a dangling pointer or buffer overflow may be extremely destructive. When data integrity is not compromised, try to put aside the shelf and tell the visitor that although some features are not perfect, she can try again. A good helper that is often overlooked is the standard set_error_handler () function. This is another example-this is a basic event-encapsulated into a centralized location where all code is dedicated to handling these basic events. If you want to keep all event logs with errors to identify duplicate issues, you should do this here.

Before we end our low-level programming discussion, there is another saving-on technique. In PHP5, by default, an object reference is assigned or transferred (the reference is the object handle, not the object itself or a copy of the object ). As long as we still need to use PHP4, we must pay attention to the object transmission method. Some nuances may make you restless. For example, the following statement causes $ obj2 to become a copy of $ obj1. this is not surprising.

$ Obj2 = $ obj1;

The function will use the copy and return the copy, unless otherwise specified-we have to accept this situation. The following example causes many errors that are difficult to trace:

Class ObjectKeeper {
Var $ _ obj; // Whatever object is
Function & get_object (){
Return $ this-> _ obj;
}
}
// References can be returned well. Now the trap appears:
$ Keeper = new ObjectKeeper ();
$ Obj1 = $ keeper-> get_object ();
$ Obj1-> modify ();
$ Obj2 = $ keeper-> get_object (); // Ask new reference to same object
If ($ obj2-> is_modified ()){
Echo 'OK'; // This will never be printed
}

The correct statement should be:

$ Obj1 = & $ keeper-> get_object (); // note that "= &" is not "="

If no = & is returned, the copy of the object to which the returned reference points is assigned to $ obj1, no matter what operations you think the reference is correct, it does not affect the status of the original object. In other words, your updates will be lost.

Templates may be helpful in coordinating the culture of Web designers and programmers. They usually include everything in the layout (mainly HTML code), while the template engine fills in all variable content when generating pages. Most template engines provide a high-speed cache mechanism to ensure that resource-consuming processing only occurs when data source updates require such processing.

Next Step


Forum: PHP on Oracle

PHP roaming guide

Open source code Developer Center

Oracle + PHP troubleshooting guide

PHP scripting: arbitrary code is becoming increasingly popular

Oracle + PHP getting started

Install Oracle, PHP, and Apache on Linux

The template engine allows the layout and graphics to be divided at one end to a large extent, and the business logic to be divided at the other end. The most popular template engine may beSmartyIt is also integrated into many open-source CMS and framework projects.

Finally, you must note that when the logic exceeds the replacement of the basic search substitution type, the template engine tends to provide programming dialects. Future methods are likely to rely on XSLT technology, and XML extension support in PHP5 will change a lot.

Finally, it is a very important practice: reuse first-class code from a well-known library. Our research will be limitedPEARBecause it is now part of the standard PHP release.

PEAR may be closer to the real standard PHP software components. Strict selection of providers and strict quality standards ensure that components are as good as commercial components. Version control conventions provide you with precise control to determine which version of the component is suitable for your application. PEAR provides a wide range of functions from form processing to the database abstraction layer (PEAR: DB), including advanced features such as Web services or WebDAV support.
Needless to say, by familiarizing yourself with PEAR and similar PHP code libraries, you can save a lot of days of intense R & D work.

PHP5

PHP has made itself one of the greatest success stories of open source code, and is in parallel with Linux and Apache. Although there are still some disadvantages, IT has been firmly established in the IT industry, and its large grassroots user base still enjoys IT.

PHP5 may facilitate the development of heavy Web applications. The business logic layer that interacts with the database is increasingly accepting PHP code. At the same time, flexible programming methods will increasingly use XML technology, making it easier for Web designers to collaborate with developers and software designers without friction.
We look forward to seeing the next generation of PHP-based Web applications that are very attractive and useful.

Structured PHP is mature, so it is time to quickly compile out-of-the-box scripting staff and understand the UML object-oriented developers to "reach an agreement. Few programming languages...

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.