I know many Java and .NET developers who often like to make fun of PHP. Honestly, a couple of years ago I was one of them. I used the next arguments to set Java and .NET above PHP (this is my personal opinion):
- It is not a good idea to use dynamic typization in a server-side language, because server is all about performance and security – static typization supports these two attributes a lot. Also, static typization makes code refactoring much easier.
- Java and .NET have much better-thought standard libraries. In PHP, you have many different ways to do the same operation – it increases code fragmentation, especially if you work in a large team of PHP developers.
- Java and .NET have more graceful syntax. $ sign in variable names, -> instead of ., <?php ?> tags make PHP code quite bulky.
Nevertheless, PHP has one great feature that makes it very useful for me. From its very beginning, PHP was designed as HTML code preprocessor. Its syntax serves this purpose perfectly. Ultimately, if you write pure HTML code in your PHP file, PHP interpreter will give you this HTML in output. Only PHP insertions between tags like <?php ?> and <?= ?> will be interpreted as PHP code. It lets you do anything with your HTML output and it is usually more convenient compared to various HTML template engines, because template is just a template – it doesn’t let you write code. Also PHP doesn’t care about what exactly you write into output: HTML, operation progress, or message log. I found it convenient for me to build JSON files with PHP.