Top 10 Wrong Ideas About PHP
- PHP is not a compiled language (it is interpreted)
- PHP cannot do X (access memory, control hardware devices, or some unusual purpose)
- PHP cannot do something that can be done in language X
- PHP is only for Web development
- PHP is controlled by only one company (Zend)
- PHP documentation is bad or insufficient
- PHP projects are not reusable because they are not Object Oriented
- PHP is worse than Ruby On Rails, Python Django, X language Framework
- PHP is not good for high performance scalable Web sites or applications
- PHP developers are cheaper because they are not qualified
- PHP is not a compiled language (it is interpreted)
- A compiled language is one that needs to convert source code in that language into a sort of machine code before it can be executed.
- An interpreted language is one that allows its code to be executed directly from the source text without a compilation step (convert source text into executable machine code).
- PHP is not an interpreted language since PHP 4, which was launched in the year 2000.
- When a PHP script is executed, first the PHP source code is compiled by the Zend engine into machine code data named Zend opcodes. These opcodes are stored in the RAM. Then those opcodes are executed to actually run the script.
- Diagram of the compilation of PHP source code into Zend Engine opcodes
- So PHP is really a compiled language just like Java, C# and others. Otherwise it would be rather slow.
- Usually the compiled PHP machine code (Zend opcodes) are not saved to files because it is not necessary. But if that is important to you, there are extensions that can output compiled PHP code to files.
- By default, if you run the same script again, PHP source code needs to be recompiled into the RAM every time it is executed. However, there several opcode caching extensions that can save the compiled PHP opcodes to shared memory, so next time a PHP script executed for a different Web server request, the original source no longer needs to be recompiled. It is just loaded from shared memory, thus saving a lot of processing time.
- The use of an opcode cache extension is thoroughly recommended for performance reasons, especially on busy sites. There are several free opcode caching extensions that you can use.
- So, as you may understand by now, the PHP code execution engine is quite sophisticated these days. But if you need something even more sophisticated, there is the HipHop for PHP compiler. This is an Open Source project developed by Facebook to take the PHP performance to the extreme. It compiles PHP source code into C++, which is then compiled into native machine code into a single Web server binary or a standalone executable program. Facebook uses it to run most of their site.
- There are also other PHP compiler projects that convert PHP code into Java bytecodes or .NET assemblies. More details can be found on the PHP compiler performance article already mentioned above.
PHP cannot do X (access memory, control hardware devices, or some unusual purpose)
- PHP is an extensible language. If you need something that the main PHP distribution does not implement, you can create PHP extensions, usually by writing some C or C++ code. So PHP can do anything that C or C++ can do.
- There are tens, if not hundreds of PHP extensions. Many of them are shipped built-in the main PHP distribution. If you need something that is not built-in PHP, you can always check the PECL PHP extension repository. This is the official repository for less popular PHP extensions written in C or C++ code.
- If there is no extension to do something that you need, maybe that is because you have an unusual need. Probably you are addressing a new problem or it is something that nobody else has a need for. So, you can always develop a new extension yourself. If you are not capable of developing C or C++ code, you can always hire another developer to do it for you. So you are never stuck without a solution.
PHP cannot do something that can be done in language X
- I doubt that there many relevant things that you cannot do in PHP that you can do in other languages. Maybe you can do things in other languages using different programming styles but that does not mean that you cannot develop the same features in PHP, given all the available PHP extensions.
- Still, if you find something that can only be done in some other language or you have to rely in existing components written in that language, you can always try to interface with code written in other languages using special PHP extensions available for that purpose.
- Oh, wait, there is no Ruby extension for PHP as you may have noticed. As I said, that is probably because nobody has such an odd need. Still, if you really have that need, maybe you can convert Ruby into Java using JRuby and then you can use the PHP Java extension to run the converted Ruby code. The same goes for other less popular languages.
- It is a long shot that may make you wonder if it really makes sense, but at least PHP does not leave you without a solution.
PHP is only for Web development
- PHP most common use is indeed for Web application development. Still you can run PHP outside a Web server using the PHP CLI (Command Line Interface) executable. It is a program that can be started from the command line shell for performing all sorts of operations, being Web site related or not.
- Even CPU intensive applications are developed in PHP and run outside a Web server using the PHP CLI program, like for instance sending newsletters to many subscribers. The PHPClasses itself sends millions of newsletter messages every month using the PHP CLI program.
- You can even create desktop applications to run on Windows, Linux, Mac or any other Unix flavor using the PHP-Gtk extension. You can also develop Windows specific applications or even Windows services using extensions like WinBinder and other PHP Windows specific extensions.
- It is not as if there is great demand for developing these kinds of operating system specific applications, but if you need them, you can develop them in PHP too if you want.
PHP is controlled by only one company (Zend)
- If you have already read about the PHP history you can realize that PHP was created by Rasmus Lerdorf in 1994. Over time Rasmus was joined by tens or even hundreds of other developers, including Andi Gutmans and Zeev Suraski, the founders of Zend, as well other core developers that work (or at least worked) for Zend.
- I think it is only natural that Zend developers will always try to influence PHP development, so it takes directions that are convenient to their business. After all they have invested their whole business in PHP. If PHP development takes a route that makes Zend irrelevant, it would probably kills their business.
- Still stating that PHP developement is controlled only by one company seems to be a great exaggeration. The fact is that PHP was developed and continues to be developed by many more people that are not associated with Zend.
- There are even core developers that work for Microsoft, like Pierre Alain Joye, a long time PHP core developer that was hired by Microsoft in the recent years to make PHP run well with Windows and other Microsoft products. There are also developers from Oracle, not just to take care of Oracle database extensions, but also MySQL, which is now also an Oracle product since they acquired Sun.
- The fact is that those PHP core developers that are connected to Zend, Microsoft, Oracle or other companies, are just a minority, despite their influence. The majority of core developers are not connected with any company.
- If you are concerned that those companies can be evil and try to influence the development of PHP to go in the wrong direction, rest assured that all the other core developers that are not tied to any company are also concerned and watching out for any wrong moves. If you tried to watch the discussions in the PHP internals list for a while you probably have already realized that.
PHP documentation is bad or insufficient
- If there is only one good thing about PHP, that is certainly the documentation. The documentation is well structured, clear and, given the necessary time to the documentation team, very complete. The user comments that appear in documentation pages only make it even more rich and complete.
- I have yet to see any other software project, Open Source or not, that has better documentation than PHP. The fact that it includes user comments qualify the PHP documentation project to be titled: Documentation 2.0 - used enhanced documentation.
- The PHP documentation team does an amazing job. Not only they take care of the main documentation in English, but they also have teams dedicated to translate it to tens of other idioms. That is certainly part of the reason why PHP is so popular everywhere in the world. Kudos to everybody that helps in the PHP documentation.
- Still the PHP documentation team cannot do miracles. The aspects that PHP covers are so extensive, that it is impossible to know every obscure detail that may make PHP work in a different way that it is expected in certain platforms. There can be bugs in PHP that may cause incorrect behavior, but that is not the fault of the PHP documentation team.
- That is why the user comments are so important. They provide additional information that lets other PHP users learn about unexpected behavior that the documentation team could not anticipate.
- Additionally, you may often find in documentation user comments sample code to perform certain tasks that PHP users wished that PHP functions could do. That makes PHP documentation with user comments even richer than it would be without the comments. Isn't that amazing?
- One of the reasons why PHP got so popular is the due to several killer applications that dominate the Web market. Several of them come to my mind like Wordpress, Drupal, Joomla, etc.. If you want to work as a PHP consultant, chances are that a good part of your clients will want you to integrate their sites with some of these applications.
- Nowadays Wordpress is certainly the most popular of the PHP killer applications. Recently, Matt Mullenweg, the creator of the Wordpress project, announced in his State of the Word 2011 speech that Wordpress is present in 14.7% of the top one million Web sites according to the W3 Techs Web survey. That is a lot!
- Matt also commented that many developers tweak their Wordpress installations with plug-ins to make it work as a CMS or eventually other types of applications.
- Still Wordpress code is mostly written in non-Object Oriented code. It ships with same base classes to implement some common functionality, but the core functionality is written in procedural code.
- This makes evident the fact that not being written with Object Oriented code is not necessary to make the project reusable, even for other purposes that are way beyond the original blogging platform purpose.
- But wait, do not get me wrong. This is the PHPClasses site. One of the rules that is mandatory to have PHP components accepted for publication in the PHPClasses site, is that the code that implements the described functionality must be written in the form of classes of Object Oriented code, thus the name of the site: PHP Classes.
- The reason for this requirement is that classes encapsulate functionality inside a container called a class. If component functions were global, there would be a greater chance of name clashing when combining multiple components of different sources.
- For instance, if two components had a function named "print" , how would the applications tell which of the components they want to call the function print? Classes make it easier to encapsulate functions with the same names within different scopes.
- But there is a workaround to avoid that problem without resorting to classes. You can just add a prefix to the functions of each component in order to avoid name clashing. For instance, the MySQL extension provides functions with the prefix mysql_.
- This is a very old solution used in the core PHP functions since ever, specially because until version 3 there was no Object Oriented support in PHP. But this practice was kept throughout the years even until today.
- Admittedly it is not an elegant solution. Component function name clashing (encapsulation) is just one of the benefits of Object Oriented Programming. But nobody can say that it does not work, or that it prevents PHP projects from being reusable.
- PHP comes with many extensions that provide many features but comparing a language with a full stack framework is like comparing pines with apples.
- It is fair to compare PHP with Java, C#, Ruby, Python, or "insert the language of the jour here". It is also fair to compare Ruby on Rails, Django, etc.. with a similar PHP framework. As a matter of fact there are so many similar frameworks in PHP, that we are not mentioning anyone in specific here to avoid being unfair to the fans of each of them.
- Personally we think that what the developers of any language need is not exactly to use a framework. What developers need is to embrace a methodology of development that makes them productive.
- Once you adopt a consist development methodology, everything becomes mechanic and you take less time to produce that same volume of work, as you just need to repeat the same development steps consistently.
- You do not really need to use a specific framework to adopt a consistent development method. For instance, we do not use any framework. we just follow the same development methodology that we have been evolving over the years, so nowadays we are quite productive using that methodology.
- We follow good development practices like separating concerns into different code components, but we do not need any MVC framework. Actually we feel that MVC is often an inadequate design pattern for use in the development of scalable Web applications.
- We usually separate application concerns in components that are can be distributed easily among different machines by the means of service layers. But that may be a subject for a different post.
- The main point here is that you do not need to use the framework X to be productive. What matters is that you follow a consistent development methodology that makes your work mechanic and fluent.
- The fact is that certain frameworks impose a certain development methodology. Those frameworks are being called "opinionated" because they reflect the opinion of their creators about how development should be.
- So, if you invested in studying a methodology that a certain framework imposes and that makes you productive when you implement your Web applications, fine, stick with it.
- But please do not come and tell that the framework X, of which you are a big fan, is the best solution, or worse like saying that PHP developers cannot be equally or more productive than you just because they do not use that other language framework that you love so much. That is just your opinion based just in your own experience. Do not underestimate other developers' experience.
- The way I see it, performance and scalability are not a matter of language, but rather a matter of application architecture.
- When it comes to performance, as mentioned above, PHP is a compiled language, so its is speed is nowadays very good for most Web application purposes.
- Facebook is certainly the largest site that was developed in PHP. They do not seem to have scalability issues due to their adoption of PHP.
- It is true that they developed their own PHP to C++ compiler to make PHP applications run at top speed. It is also true that for CPU intensive applications, the gains of compiling PHP into a lower level language can be significant.
- However, the reality is that most Web applications are not CPU intensive. For instance, one of the activities that Web applications spend most time on is accessing databases.
- When your application executes a SQL query, most of the time is spent waiting for the database server to execute the query and return the results. Waiting for a query to execute on a database server in PHP or in a lower level language like C++ is going to take practically the same amount of time.
- So, now you may wonder, if PHP can be in practice equally as fast as C++ for database based Web applications, why did Facebook people went through such a great effort to develop a PHP to C++ compiler?
- The answer lies in the fact that they also changed the architecture. They do not just compile PHP into C++. They take the scripts of whole PHP applications, compile them into single ball of C++ code and generate a single executable that works as a multi-threaded Web server. Notice the emphasis on the multi-threaded word.
- Multi-threaded Web servers use a single process to handle many simultaneous HTTP requests. That saves them a lot of RAM because multiple threads share the same memory pool. This means that they end up needing less Web server machines to handle the same load. For a company like Facebook that has thousands of server machines, the gains are significant.
- For most other smaller Web sites, the gains are probably not significant enough to go through the effort of compiling PHP into C++.
- That does not mean you should not make an effort to educate yourself to learn and to adopt good architecture optimization techniques. Many of those techniques have been covered in this blog in the PHP performance articles category. Go and read them when you can.
- Still, most of those techniques are not language specific. You should adopt them regardless whether you develop your applications in PHP or other languages.
- The economy works all in terms of offer and demand. If there is a product that is wanted by many customers and there is not enough quantity of the product on the market for sale, the prices tend to go up. On the other hand, if the product is abundant on the market and the customers are not buying it much, the prices tend to go down.
- The same goes for jobs. If there are more companies looking for qualified candidates than those that are available for hire, the offered salaries tend to go up. On the other hand, if there are more candidates than companies willing to hire them, the offered salaries may go down.
- The PHP market is huge because the Web is huge. There are many companies willing to hire qualified PHP Web developers. But for simpler jobs, they do not want to pay much because they can find plenty of candidates with sufficient qualifications. Those jobs can be as simple as installing and customizing existing PHP applications.
- But for companies that need to hire developers that not only know PHP, but also have other more sophisticated skills like application architecture planning and deployment, developing high scale Web sites, handle security matters properly, search engine optimization, etc., companies tend to pay much better salaries because developers with all those qualifications are scarce.
- So, it is not so much a matter a problem of the PHP developers. It is more a matter of the qualifications that are demanded by the types of PHP jobs that require PHP skills.
PHP projects are not reusable because they are not Object Oriented
PHP is worse than Ruby On Rails, Python Django, X language Framework
PHP is not good for high performance scalable Web sites or applications.
PHP developers are cheaper because they are not qualified
Well, the list of misconceptions about PHP does not end here. We just listed a few that we found more important.
A good professional should know more than just one language to eventually take more advantage of the opportunities that may show up in their careers. So our advice is that whether you love or hate PHP, do not just stick to PHP or that other language that you prefer instead of PHP.