After PHP has matured

Source: Internet
Author: User
Tags pear php programming php software
As PHP is maturing, it is time for fast, ready-to-use scripting people to agree with the idea of an object-oriented developer who understands UML.
Few programming languages can be popularized as quickly as PHP. The story of the widely publicized scripting language that changes the IT industry shows that success does not always come from system planning and market research. But the real question now is how this success can be embraced by the huge IT industry. Oracle and several other big players are focusing on PHP. The fact is that the language is ripe.
Until now, success has only just "appeared". The growing number of enthusiasts has gathered around PHP, as if gathered around a genius prodigy. But since the child is growing a beard and starting to talk to adults on an equal footing, will early advocates adapt to this change?
PHP, like most major open source projects, is a fundamental phenomenon in the process of becoming a mainstream technology. Will PHP disappoint the people who make it a reputation? Will it meet the expectations of a huge IT industry?
The story of two kinds of programming culture
The success of PHP has attracted the attention of people from different backgrounds. Early advocates of Rasmus (if you can forgive those who do not often appear in the open-source code to be a bit of a savior) are accustomed to a fast, ready-to-use scripting approach, and they now have to deal with developers who understand UML, object-oriented (OO) programming, who are determined to make PHP Keep abreast of other modern development tools. Both are well aware of WEB development and have a strong culture. It is unwise to ignore either side.
What are the early PHP types that understand what WEB development is, what it excels at, and what is not good at doing? It knows a lot about design issues. Its style can sometimes be problematic, but it can be seen that it has HTML and CSS features, not to mention the more popular multi-information Internet application (RIA) technology. It is always so young, but often appears in the PHP forum. The term "object-oriented" may have negative implications for it. Its code is very concise, focusing on performance and not on maintainability.
Due to the use of loosely typed variables and the filling of their HTML code Statement, the UML type will be less appealing. It will consider application architecture, class-level code reuse, team collaboration, and source code control. It knows that even moderately complex sites are first and foremost applications, and poorly designed applications can cause delays, annoy customers, and even lose their jobs.
At first glance, the latter seems to be more adapted to an increasingly demanding environment in which WEB development will increasingly be driven by marketing strategies and economic factors. But should we see the former as an endangered species? Maybe it shouldn't be. If we admit that the WEB is a medium that is very different from desktop systems-let's not say mainframe anymore (Does anyone remember 3270?) ), creating a dominant development approach in mainframe environments – we may conclude that, after all, it is possible to learn something good and effective from this successful but relatively messy approach.
Let us review the practical issues in order to overcome them before they can occur and to review some practical ways of working.
Bridging the cultural gap
Now PHP5 is about to bring object-oriented technology into the PHP world. Zend Engine Modification (ZE2) is introducing an object to the core of the language. Not only are new language constructs encouraging object programming styles, but language implementations are also adapting to other object-oriented environments. For example, objects are no longer copied back and forth by default, but are processed by reference. New keywords, such as final or static, are introduced that are only relevant to the concept of an object and are reserved for Java-style, and other attributes, such as delegates, encourage the use of object design patterns. (I look forward to hearing about the "original PHP4" in a few months ' time. This profound change comes from a relentless and revolutionary shift to the current dominant programming model. Whether you like it or not, the object approach will be popular because it has proven itself most effective in providing complex applications, whether they are Web applications or not. This leaves us no choice but to find imaginative ways to reconcile two cultures so that people with design ideas and those who understand the architecture can complement each other.
To do this, various methods must be developed (or transformed from other platforms) to allow for the versatility of the language while it is contained within a clear boundary. In this way, the "island" of programming creativity can exist in a robust architecture.
One obvious fact is that, despite the explosive growth in the number of PHP CMS or application frameworks, there is no consensus on them. The recurring complaint is that no matter what your project is, the existing system cannot complete the task. Most people begin to evaluate several systems, and in the end they often develop their own frameworks from scratch. Why is this?
In the desktop system, it seems that the GUI design problem has been completely solved by the operating system, in contrast, the Web is a very important platform for the original visual design. Web sites that host the image and personality of a business company may increasingly affect their revenue. Visual creativity works with brands, so they must be promoted.
At the same time, you must be able to incorporate flexible logic into your application in order to improve the user experience as much as possible, keeping in mind that users are more "food" on the Web than they might appear on a desktop system.
This is a problem when designers are constantly frustrated with the system the programmer is designing, which is also a problem when developers have to force application code into an incomplete portal framework. The most common outcome is an unsatisfactory compromise-some stiff looks, and a lot of usability at the expense of limiting the complexity of the application to a manageable level. (This behavior is not limited to PHP applications.) )
To overcome these limitations completely, designers and object-oriented developers must find a collaborative approach that does not hinder their work. The best approach may be to start by understanding how the opposing team works.
From skill to industry
Don't think about collaboration at the moment, let's look at the actual operation. Let's start with the historical order of PHP, and first visit a store where the "enhanced HTML" consumer is used.
The tool for trading is very similar to the "pure HTML" consumer's tool: some HTML editors with various levels of comfort and project management features, and to some extent integrate with PHP, ASP, JavaScript, and lesser tools.
Let's take some time to look at the code carefully. We'll start by noticing that the sites generated using these different kinds of tools are very beautiful. We are not only referring to technology here, but also to talent. Free from the limitations of abstract programming factors, WEB Designers create a visual environment that makes your site's customers feel comfortable by fiddling with positive, subtle emotional effects, similar to the effects that smart decorators create in a real store.
When we look at the code from the perspective of a trained object-oriented programmer, things suddenly get really bad. The code looks like it itself: it's a one-time, out-of-the-box job that doesn't make any preparation for future development or for easy maintenance. Often, it does.
So, what's wrong with that? Will it become a problem later, leading to the abandonment of parts or the entire site and rebuilding from the beginning? Maybe not. After all, the decoration of real shops is often demolished and rebuilt regularly. So the cowboy-style PHP programming is enough for these showcase sites. This language is rich in all sorts of techniques that help to achieve visual effects that are designed to attract visitors ' attention. This is obviously irrelevant to the object method.
When certain application logic is needed, there is a significant change in this view. Do you need a few forms to collect a small amount of marketing information about your website's regulars? If you want this information to be pertinent, it's a good idea to add a checksum code. If you do this, you should make sure that you can filter out malicious scripts or SQL command intrusive attacks. By the way, since you are reading the OTN article, you must be familiar with database (db) issues. The information you are about 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 site has been pinned to your business infrastructure-it's becoming a mature application.
For the time being, we leave all of its hard-coded links, dangerous type conversions, and security holes, and then access the latest PHP object-oriented application assembly line. For our artist-style Web designers, this place may not be familiar or even unfriendly. There is less emphasis on skill here. WEB development has been industrialized. To be accepted here, you must be familiar with classes, inheritance, data abstraction, and a large number of code encapsulation tools.
Team collaboration requires rules. Programming conventions must be followed; source files must be submitted for versioning and source control. Files are organized according to a rigorous modular hierarchy. Discard the risky coding techniques-especially the tricks that are smart. The code must not only be readable, but must be well commented.
This may be annoying, but it works. Now we are creating WEB applications: Intranets, commercial WEB sites, electronic marketplaces, various applications where flawed design can lead to closure. In short, we are overcoming complexity.
PHP's object-oriented assembly line managers did not choose PHP because they loved the language. They do this because they are not only able to do their work as effectively as other languages, but are free and without any strings attached.
Where are we headed?
So how will we leverage the industry-class approach provided by people trained in C + + and Java to complete the potential for expertise in the multi-functional language used by early adopters?
PHP5 will shake many habits, so the problem may be premature. Some will be forced to adopt a certain level of object-oriented approach, while others will eventually learn all about object-oriented content and become believers in it. Some small environments may run as well as they did in the past and continue to thrive.
Let's try to practice
Now let's dive into the basic technical level, learn how to develop simple habits, and find simple and effective solutions that will help us prepare for the changes that are coming. A large number of very simple conventions help to promote programming and prepare the application for expansion.
Naming conventions (the habits of C + + programmers) is the easiest way. If you have already used a large number of code libraries (for example, PEAR), it might be a good idea to use their conventions as your own, otherwise you should develop your own internal rules. Simplified Hungarian notation (named according to its Hungarian inventor Charles Symonyi) can be applied extensively in the range allowed by loose types. You can also use underscores as a prefix for class members. Another useful habit is to append a special prefix (such as Impl_) to a method that is not intended to be called from outside the class (a function that belongs to a class).
Whatever naming convention you adopt, make your code as clear as possible. In this way, a trained person might find a programming error in PHP fullscreen, just because it looks problematic, like a stain on a portrait.
Another important aspect of naming conventions is avoiding name collisions, making it possible to reuse code in a wide range. Experience has taught us that programmers are not always very imaginative in naming programming objects. It is possible that there are many page classes, and it is not possible that when you want to reuse the two page classes, you find that they are only the same name and have different uses. That's not a good luck. In the long run, renaming will lead to maintenance problems. You'd better avoid this problem from the start. Generating GUIDs will be overkill, unsightly (e.g. _16b280c5_ee70_11d1_9066_00c04fd9189d_page! ) and contrary to the spirit of PHP.
A simple way to prevent collisions is to ensure the uniqueness of the inner classes by associating several different aspects of the class into their names (for example, Gallerypage), and then, to eliminate the possibility of conflicts with classes outside your control, you can press Java The reserved version of the domain name you own as its prefix (com_mydomain_gallerypage).
Another habit you want to develop doesn't require you to spend, and when an unexpected change in an application scope is unavoidable, it can save you the job of encapsulating the most common basic statements in a single 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 you need to preprocess or redirect output in a new environment, you know where you should write the few lines of code you need without having to face the frustrating situation of 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 (dangling pointer) or a buffer overflow can be extremely destructive. When the data integrity is not compromised, try to put down the shelf to 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-this time the basic event-encapsulated into a centralized location where all the code is dedicated to dealing with these basic events. If you want to keep all event logs that have errors in order to identify recurring problems, you should do this here.
There is another life-saving trick before we end the low-level programming discussion. In PHP5, by default, an object reference is assigned or passed (the reference is the handle to the object, not the object itself or a copy of the object). As long as we need to use PHP4, we must pay careful attention to the way objects are delivered. Some subtleties may make you uneasy. For example, it is not surprising that the following statement causes $obj 20% to be a copy of $obj 1;
$obj 2= $obj 1;
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 track:
Class Objectkeeper {
var $_obj; Whatever object is
Function & Get_object () {
return $this->_obj;
}
}
The reference can be returned in a good way. Now the traps appear:
$keeper = new Objectkeeper ();
$obj 1 = $keeper->get_object ();
$obj 1->modify ();
$obj 2 = $keeper->get_object (); Ask new reference to same object
if ($obj 2->is_modified ()) {
Echo ' OK '; This will never print
}
The correct statement should be:
$obj 1=& $keeper->get_object (); Note that it is "=&" rather than "="
If there is no =&amp, then a copy of the object that the returned reference points to is assigned to $obj 1, and no matter what you do with the reference you think is correct, it does not affect the state of the original object. In other words, your update will be lost.
Templates can be helpful in reconciling the culture of Web designers and programmers. They usually include everything that is in the layout (mostly HTML code), and when the page is generated, the template engine fills in all the mutable content. Most template engines have a caching mechanism to ensure that the associated resource-intensive processing occurs only when the data source update requires these processing.
The next steps
Forum: PHP on Oracle
PHP Rover Guide
Open Source Developer Center
Oracle + PHP Troubleshooting Guide
PHP Scripting: Arbitrary code is becoming popular
Getting Started with Oracle + PHP
installing Oracle, PHP, and Apache on Linux

The template engine allows the layout and graphics to be divided at one end to a considerable extent, with the business logic at the other end. The most popular template engine may be Smarty, which is also well-integrated in many open-source CMS and framework projects.
Finally, it is important to note that the template engine tends to provide a programming dialect when logic goes beyond the replacement of a basic search substitution. The future approach is likely to rely on XSLT technology, and the extended XML support in PHP5 will change a lot.
Last but not least, a practical aspect: reusing first-class code from well-known libraries. Our research will be limited to PEARbecause it is now part of the standard PHP release.
PEAR may now be closer to the true standard PHP software components. Strict selection of providers and stringent quality standards ensure that components are as good as commercial-grade components. Versioning conventions provide you with granular control to determine which version of a component is appropriate for your application. PEAR provides the abstraction layer from form processing to the database (PEAR::D B) A wide range of features, including advanced features such as WEB services or WebDAV support.
Needless to say, you can save a lot of days of intense research and development by being familiar with PEAR and similar PHP code libraries.
PHP5
PHP has made itself one of the biggest open source success stories, with Linux and Apache trimming. Although not ideal, it has a firm foothold in the IT community, and its huge grassroots user base still likes it.
PHP5 may facilitate the development of heavily burdened Web applications, and 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 without friction with developers and software designers.
We look forward to seeing a new generation of very attractive and useful PHP-based WEB applications.

The above is the introduction of PHP has been mature, including the content of the text, I hope that the PHP tutorial interested in a friend helpful.

  • 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.