Since PHP is maturing, it is time for fast and ready-to-use scripting workers to “confirm the idea” with object-oriented developers who understand UML.
Few programming languages are popularized as quickly as PHP. The story of scripting language changing IT industry that is widely publicized now about Do-it-yourself (DIY) shows that success doesn’t always come from system planning and market research. But the practical question now is how this success can be accepted by the huge IT industry. Oracle and several other big players are following PHP facts show that the language is mature.
Until now, success has only just "appeared". A growing number of enthusiasts have gathered around PHP as if they were gathered by a talented prodigy. But now that the child is growing a beard and starting to talk to adults on an equal footing, will early advocates adapt to the change?
PHP, like most major open source projects, is a fundamental phenomenon in the process of becoming mainstream technology. Will PHP disappoint those who make it famous? Will it meet the expectations of the huge IT industry?
The story of two programming cultures
PHP’s success has attracted the attention of people from different backgrounds. Early Rasmus advocates (if you can forgive the slightly savior tone that doesn’t appear in the open source circle) are used to fast and ready-to-use scripting methods, and now they have to deal with developers who understand UML, object-oriented (OO) programming, determined to keep PHP alongside other modern development tools. Both sides know web development well and have a strong culture. It is unwise to ignore either party.
Early PHP types understand what aspects of web development, what is it good at and what is it not good at? It knows a lot about design. Its style can sometimes be problematic, but it can be seen that it has HTML and CSS capabilities, not to mention the more popular multi-information Internet Application (RIA) technology. It is always so young, but it often appears in PHP forums. The term "object-oriented" may have negative meanings for it. Its code is concise, focusing on performance rather than maintainability.
UML types will be more inviting because of loosely typed variables and populating <?php?> statements for their HTML code. It will consider application architecture, class-level code reuse, teamwork, and source code management. It knows that even a moderately complex website is an application first, and poorly designed applications can cause delays in construction, annoy customers and even lose their jobs.
At first glance, the latter seems to be more adaptable to an environment where demand is increasing, in which web development will increasingly be driven by marketing strategies and economic factors. But should we regard the former as an endangered species? Maybe this shouldn't be. If we acknowledge that the Web is a medium that is very different from desktop systems—not to mention mainframes (and anyone remembers the 3270?), a dominant development method has emerged in the mainframe environment—we might conclude that something good and effective can be learned from this successful but relatively messy approach.
Let's review the actual problem so that it can be overcome before it can happen and review some practical working methods.
Make up for 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 are new language constructions encouraging object programming styles, but language implementation is 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, which are only related to object concepts and are reservations of Java styles; other features (such as delegations) encourage the use of object design patterns. (Looking forward to hearing everyone talk about "the original PHP4" in a few months.) This profound change comes from a ruthless shift to the current dominant programming model. Whether you like it or not, object methods will be popular because it has proven itself 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 the two cultures so that people with design ideas and those who understand the architecture can learn from each other's strengths and weaknesses.
To do this, various methods must be developed (or transformed from other platforms) to gain versatility of the language while including it within clear boundaries. In this way, the "island" of programming creativity can exist in a robust architecture.
The obvious fact is that despite the explosive growth of PHP CMS or application frameworks, there is no consensus on them. A frequent complaint is that no matter what your project is, the existing system cannot complete the task. Most people start with evaluations of several systems, and end up often developing their own frameworks from scratch. why is that?
In desktop systems, it seems that the operating system has completely solved the GUI design problem, and the Web is a platform where original visual design plays a vital role. Web sites carry the image and personality of a commercial company that may increasingly affect their revenue. Visual creativity works together with brands, so they must be promoted.
At the same time, flexible logic must be able to be compiled into the application to improve the user experience as much as possible, and it should be kept in mind that users are more "dish" on the web than they might be in desktop systems.
This is a problem when designers are constantly disappointed with the system programmers design, and it is also a problem when developers have to force their application code into an incomplete portal framework. The most common ending is an unsatisfactory compromise—somewhat rigid looks, sacrifices a lot of usability in order to limit the complexity of the application to a certain manageable level. (This phenomenon is not limited to PHP applications.)
To completely overcome these limitations, designers and object-oriented developers must find a collaborative approach that does not hinder each other's work. The best way to do this might be to start by understanding how the other team works.
From skills to industry
Don’t consider the collaboration issue at this moment, let’s observe our actual operations. Let's start with the historical order of PHP and first visit a store for "enhanced html" users.
The tools for trading are very similar to those of "pure html" users: some html editors have various levels of comfort and project management features and are integrated to some extent with PHP, ASP, JavaScript, and more minor tools.
Let's take a moment to look at the code carefully. We will first notice that the websites generated using these different kinds of tools are very beautiful. We refer not only to technology, but also to talent. Removing from the limitations of abstract programming factors, web designers create a visual environment that makes your website’s customers feel comfortable by fiddling with positive, subtle emotional effects (similar to what a alert decorator creates in a real store).
Things suddenly get bad when we look at this code from the perspective of a trained object-oriented programmer. The code looks like it itself: it is a one-time, forget-for-use work, without any preparation for future development or for simple maintenance. This is often the case, and it is indeed the case.
So, is there anything wrong with this? Will it become a conundrum in the future, leading to abandoning part or entire websites and rebuilding from scratch? Maybe not. After all, real shop renovations are often regularly demolished and rebuilt. So, for these window-style websites, denim style PHP programming is enough. This language is rich in techniques that help achieve visual effects designed to attract visitors’ attention. It obviously has nothing to do with the object method here.
This view changes significantly once certain application logic is needed. Do you need several forms to collect a small amount of marketing information about frequent visitors to your website? If you want this information to be quite pertinent, it is best to add a verification code. If you do this, you should make sure that you can filter malicious scripts or SQL directive intrusive attacks. By the way, since you are reading an OTN article, you must be familiar with database (DB) issues. The information you are going to collect will be stored in certain 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 full-fledged application.
Let's ignore all of its hard-coded links, dangerous type conversions, and security vulnerabilities for the time being, and then access the latest PHP object-oriented application assembly line. For those of us web designers with an artist-like style, this kind of place may not be familiar or even unfriendly. I don't pay much attention to skills 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.
Teamwork requires rules. Programming conventions must be followed; source files must be submitted for version management and source code management. Documents are organized according to a strict modular level. Abandoned those dangerous coding techniques—especially those clever tricks. The code must not only be readable, but must also be well commented.
This may be boring, but it works. Now we are creating web applications: intranet, commercial web sites, electronic markets, various applications where flawed designs can lead to business outages. In short, we are overcoming complexity.
PHP object-oriented assembly line managers do not choose PHP because they love the language. They do this because it not only does the job as efficiently as those proprietary other languages, but it is also free and without any additional conditions.
Where are we going?
So how will we take advantage of industry-level approaches provided by those trained in C++ and Java to complete potential complements to the expertise of multi-language used by early users?
PHP5 will shake a lot of habits, so this may be too early. Some will take a certain level of object-oriented approach, while others will eventually learn everything about object-oriented and become believers of it. Some small environments may operate well and continue to flourish as they used to be.
Let's practice it
Now let's dive into the basic technical level and understand how simple habits can be developed and how finding simple and effective solutions will help us prepare for the changes that are coming. A lot of very simple routines help facilitate programming and make the application ready for scaling.
Naming conventions (the habits of C++ programmers) are the easiest way to do this. If you have used a codebase (such as PEAR), it might be a good idea to have its conventions as your own; otherwise you should make your own internal rules. The simplified Hungarian annotation (named according to its Hungarian inventor Charles Symonyi) can be widely used within the scope permitted by loose types. You can also use an underscore as a prefix for class members. Another useful habit is to append a special prefix (e.g. impl_) to methods that are not used to make calls from outside the class (functions belonging to a class).
Whatever naming conventions you use, make your code as clear as possible. In this way, trained personnel may find programming errors in the screen full of PHP, just because it looks problematic, like a stain on the portrait.
Another important aspect of naming conventions is to avoid name conflicts, making it possible to reuse code on a wide range. Experience tells us that programmers are not always very imaginative when it comes to naming programming objects. It is very likely that there are many Page classes, and it is not impossible that when you want to reuse two Page classes, they only have the same name but are very different in purpose. Really unlucky enough. Renaming will bring maintenance issues in the long run. You'd better avoid this problem from the beginning. Generating a GUID will be overkill and ugly (e.g. _16B280C5_EE70_11D1_9066_00C04FD9189D_Page!) and is contrary to the spirit of PHP.
A simple and preventable way is to ensure uniqueness of the inner class by associating several different aspects of the class into its name (such as GalleryPage); then, to eliminate the possibility of conflicting with classes outside of your control, you can prefix the reserved version of the domain name you own as its Java-like (com_mydomain_GalleryPage).
Another habit to develop doesn't cost you anything, and it can save you work when unexpected changes in a certain application-wide are inevitable, which is to encapsulate the most commonly used basic statements in a separate channel. For example, besides debugging code, there should be only one "response" statement throughout the application, which should be in a certain function (or a separate class method). If you need to preprocess or redirect the output in a new environment, you know where to write the few lines of code you need without having to face the frustrating situation of searching and editing large amounts of files.
Error handling does not have to be as strict as in C++ — in C++, a dangling pointer or buffer overflow can be extremely destructive. When data integrity is not jeopardized, try to put down your shelves and tell the visitor that although some of the features are not perfect, she can try again. A good helper who is often overlooked is the standard set_error_handler() function. Here is another example of — this time, basic events — encapsulated into a centralized location where all code is dedicated to handling these basic events. If you want to keep all the event logs of errors in order to find duplicate issues, you should do this here.
Before we finish the low-level programming discussion, there is another life-saving move. In PHP5, by default, object references are allocated or passed (references are handles to objects, not objects themselves or copies of objects). As long as we still need to use PHP4, we must pay close attention to the way objects are passed. Some subtleties can 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 a copy and return a copy unless otherwise specified - we have to accept this only. The following examples lead to many difficult to track errors:
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 print
}
The correct statement should be:
$obj1=&$keeper->get_object(); // Note that it is "=&" instead of "="
Without =&, a copy of the object pointed to by the returned reference is assigned to $obj1, and no matter what you do to the reference you think is correct, it will not affect the state of the original object. In other words, your update will be lost.
Templates can go a long way in coordinating the culture of web designers and programmers. They usually include everything (mostly HTML code) that is equipped in the layout, and when the page is generated, the template engine fills in all the mutable content. Most template engines come with a cache mechanism to ensure that the processing of related resource-consuming resources only occurs when data source updates require these processing.
Next steps
Forum: PHP on Oracle
PHP Roamer's Guide
Open Source Developer Center
Oracle + PHP Troubleshooting Guide
PHP scripting: code that you want is becoming more popular
Getting started with Oracle + PHP
Install Oracle, PHP, and Apache on Linux
Few programming languages are popularized as quickly as PHP. The story of scripting language changing IT industry that is widely publicized now about Do-it-yourself (DIY) shows that success doesn’t always come from system planning and market research. But the practical question now is how this success can be accepted by the huge IT industry. Oracle and several other big players are following PHP facts show that the language is mature.
Until now, success has only just "appeared". A growing number of enthusiasts have gathered around PHP as if they were gathered by a talented prodigy. But now that the child is growing a beard and starting to talk to adults on an equal footing, will early advocates adapt to the change?
PHP, like most major open source projects, is a fundamental phenomenon in the process of becoming mainstream technology. Will PHP disappoint those who make it famous? Will it meet the expectations of the huge IT industry?
The story of two programming cultures
PHP’s success has attracted the attention of people from different backgrounds. Early Rasmus advocates (if you can forgive the slightly savior tone that doesn’t appear in the open source circle) are used to fast and ready-to-use scripting methods, and now they have to deal with developers who understand UML, object-oriented (OO) programming, determined to keep PHP alongside other modern development tools. Both sides know web development well and have a strong culture. It is unwise to ignore either party.
Early PHP types understand what aspects of web development, what is it good at and what is it not good at? It knows a lot about design. Its style can sometimes be problematic, but it can be seen that it has HTML and CSS capabilities, not to mention the more popular multi-information Internet Application (RIA) technology. It is always so young, but it often appears in PHP forums. The term "object-oriented" may have negative meanings for it. Its code is concise, focusing on performance rather than maintainability.
UML types will be more inviting because of loosely typed variables and populating <?php?> statements for their HTML code. It will consider application architecture, class-level code reuse, teamwork, and source code management. It knows that even a moderately complex website is an application first, and poorly designed applications can cause delays in construction, annoy customers and even lose their jobs.
At first glance, the latter seems to be more adaptable to an environment where demand is increasing, in which web development will increasingly be driven by marketing strategies and economic factors. But should we regard the former as an endangered species? Maybe this shouldn't be. If we acknowledge that the Web is a medium that is very different from desktop systems—not to mention mainframes (and anyone remembers the 3270?), a dominant development method has emerged in the mainframe environment—we might conclude that something good and effective can be learned from this successful but relatively messy approach.
Let's review the actual problem so that it can be overcome before it can happen and review some practical working methods.
Make up for 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 are new language constructions encouraging object programming styles, but language implementation is 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, which are only related to object concepts and are reservations of Java styles; other features (such as delegations) encourage the use of object design patterns. (Looking forward to hearing everyone talk about "the original PHP4" in a few months.) This profound change comes from a ruthless shift to the current dominant programming model. Whether you like it or not, object methods will be popular because it has proven itself 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 the two cultures so that people with design ideas and those who understand the architecture can learn from each other's strengths and weaknesses.
To do this, various methods must be developed (or transformed from other platforms) to gain versatility of the language while including it within clear boundaries. In this way, the "island" of programming creativity can exist in a robust architecture.
The obvious fact is that despite the explosive growth of PHP CMS or application frameworks, there is no consensus on them. A frequent complaint is that no matter what your project is, the existing system cannot complete the task. Most people start with evaluations of several systems, and end up often developing their own frameworks from scratch. why is that?
In desktop systems, it seems that the operating system has completely solved the GUI design problem, and the Web is a platform where original visual design plays a vital role. Web sites carry the image and personality of a commercial company that may increasingly affect their revenue. Visual creativity works together with brands, so they must be promoted.
At the same time, flexible logic must be able to be compiled into the application to improve the user experience as much as possible, and it should be kept in mind that users are more "dish" on the web than they might be in desktop systems.
This is a problem when designers are constantly disappointed with the system programmers design, and it is also a problem when developers have to force their application code into an incomplete portal framework. The most common ending is an unsatisfactory compromise—somewhat rigid looks, sacrifices a lot of usability in order to limit the complexity of the application to a certain manageable level. (This phenomenon is not limited to PHP applications.)
To completely overcome these limitations, designers and object-oriented developers must find a collaborative approach that does not hinder each other's work. The best way to do this might be to start by understanding how the other team works.
From skills to industry
Don’t consider the collaboration issue at this moment, let’s observe our actual operations. Let's start with the historical order of PHP and first visit a store for "enhanced html" users.
The tools for trading are very similar to those of "pure html" users: some html editors have various levels of comfort and project management features and are integrated to some extent with PHP, ASP, JavaScript, and more minor tools.
Let's take a moment to look at the code carefully. We will first notice that the websites generated using these different kinds of tools are very beautiful. We refer not only to technology, but also to talent. Removing from the limitations of abstract programming factors, web designers create a visual environment that makes your website’s customers feel comfortable by fiddling with positive, subtle emotional effects (similar to what a alert decorator creates in a real store).
Things suddenly get bad when we look at this code from the perspective of a trained object-oriented programmer. The code looks like it itself: it is a one-time, forget-for-use work, without any preparation for future development or for simple maintenance. This is often the case, and it is indeed the case.
So, is there anything wrong with this? Will it become a conundrum in the future, leading to abandoning part or entire websites and rebuilding from scratch? Maybe not. After all, real shop renovations are often regularly demolished and rebuilt. So, for these window-style websites, denim style PHP programming is enough. This language is rich in techniques that help achieve visual effects designed to attract visitors’ attention. It obviously has nothing to do with the object method here.
This view changes significantly once certain application logic is needed. Do you need several forms to collect a small amount of marketing information about frequent visitors to your website? If you want this information to be quite pertinent, it is best to add a verification code. If you do this, you should make sure that you can filter malicious scripts or SQL directive intrusive attacks. By the way, since you are reading an OTN article, you must be familiar with database (DB) issues. The information you are going to collect will be stored in certain 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 full-fledged application.
Let's ignore all of its hard-coded links, dangerous type conversions, and security vulnerabilities for the time being, and then access the latest PHP object-oriented application assembly line. For those of us web designers with an artist-like style, this kind of place may not be familiar or even unfriendly. I don't pay much attention to skills 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.
Teamwork requires rules. Programming conventions must be followed; source files must be submitted for version management and source code management. Documents are organized according to a strict modular level. Abandoned those dangerous coding techniques—especially those clever tricks. The code must not only be readable, but must also be well commented.
This may be boring, but it works. Now we are creating web applications: intranet, commercial web sites, electronic markets, various applications where flawed designs can lead to business outages. In short, we are overcoming complexity.
PHP object-oriented assembly line managers do not choose PHP because they love the language. They do this because it not only does the job as efficiently as those proprietary other languages, but it is also free and without any additional conditions.
Where are we going?
So how will we take advantage of industry-level approaches provided by those trained in C++ and Java to complete potential complements to the expertise of multi-language used by early users?
PHP5 will shake a lot of habits, so this may be too early. Some will take a certain level of object-oriented approach, while others will eventually learn everything about object-oriented and become believers of it. Some small environments may operate well and continue to flourish as they used to be.
Let's practice it
Now let's dive into the basic technical level and understand how simple habits can be developed and how finding simple and effective solutions will help us prepare for the changes that are coming. A lot of very simple routines help facilitate programming and make the application ready for scaling.
Naming conventions (the habits of C++ programmers) are the easiest way to do this. If you have used a codebase (such as PEAR), it might be a good idea to have its conventions as your own; otherwise you should make your own internal rules. The simplified Hungarian annotation (named according to its Hungarian inventor Charles Symonyi) can be widely used within the scope permitted by loose types. You can also use an underscore as a prefix for class members. Another useful habit is to append a special prefix (e.g. impl_) to methods that are not used to make calls from outside the class (functions belonging to a class).
Whatever naming conventions you use, make your code as clear as possible. In this way, trained personnel may find programming errors in the screen full of PHP, just because it looks problematic, like a stain on the portrait.
Another important aspect of naming conventions is to avoid name conflicts, making it possible to reuse code on a wide range. Experience tells us that programmers are not always very imaginative when it comes to naming programming objects. It is very likely that there are many Page classes, and it is not impossible that when you want to reuse two Page classes, they only have the same name but are very different in purpose. Really unlucky enough. Renaming will bring maintenance issues in the long run. You'd better avoid this problem from the beginning. Generating a GUID will be overkill and ugly (e.g. _16B280C5_EE70_11D1_9066_00C04FD9189D_Page!) and is contrary to the spirit of PHP.
A simple and preventable way is to ensure uniqueness of the inner class by associating several different aspects of the class into its name (such as GalleryPage); then, to eliminate the possibility of conflicting with classes outside of your control, you can prefix the reserved version of the domain name you own as its Java-like (com_mydomain_GalleryPage).
Another habit to develop doesn't cost you anything, and it can save you work when unexpected changes in a certain application-wide are inevitable, which is to encapsulate the most commonly used basic statements in a separate channel. For example, besides debugging code, there should be only one "response" statement throughout the application, which should be in a certain function (or a separate class method). If you need to preprocess or redirect the output in a new environment, you know where to write the few lines of code you need without having to face the frustrating situation of searching and editing large amounts of files.
Error handling does not have to be as strict as in C++ — in C++, a dangling pointer or buffer overflow can be extremely destructive. When data integrity is not jeopardized, try to put down your shelves and tell the visitor that although some of the features are not perfect, she can try again. A good helper who is often overlooked is the standard set_error_handler() function. Here is another example of — this time, basic events — encapsulated into a centralized location where all code is dedicated to handling these basic events. If you want to keep all the event logs of errors in order to find duplicate issues, you should do this here.
Before we finish the low-level programming discussion, there is another life-saving move. In PHP5, by default, object references are allocated or passed (references are handles to objects, not objects themselves or copies of objects). As long as we still need to use PHP4, we must pay close attention to the way objects are passed. Some subtleties can 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 a copy and return a copy unless otherwise specified - we have to accept this only. The following examples lead to many difficult to track errors:
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 print
}
The correct statement should be:
$obj1=&$keeper->get_object(); // Note that it is "=&" instead of "="
Without =&, a copy of the object pointed to by the returned reference is assigned to $obj1, and no matter what you do to the reference you think is correct, it will not affect the state of the original object. In other words, your update will be lost.
Templates can go a long way in coordinating the culture of web designers and programmers. They usually include everything (mostly HTML code) that is equipped in the layout, and when the page is generated, the template engine fills in all the mutable content. Most template engines come with a cache mechanism to ensure that the processing of related resource-consuming resources only occurs when data source updates require these processing.
Next steps
Forum: PHP on Oracle
PHP Roamer's Guide
Open Source Developer Center
Oracle + PHP Troubleshooting Guide
PHP scripting: code that you want is becoming more popular
Getting started with Oracle + PHP
Install Oracle, PHP, and Apache on Linux