Trying out PHP after 7 years
Introduction
This post will be weird for all of my usual readers. I'm a Lead Java Developer that's been writing about fun and clever things to do in Java ecosystem. What most of you probably don't know is that prior to working in Java, I was a Lead PHP Developer for quite a while. Yup. The PHP. The language that is so divisive, that on one hand, drives more than 75% of the entire Internet and, on the other hand, is considered by many to be a pathetic, ugly scripting language, no better than universally hated JavaScript.
The Premise
7 years ago, when I was finally parting ways with PHP to focus solely on Java, I was among the PHP haters. I was fed up with weird syntax and Object Model, inconsistent naming conventions, no static typing of any kind, structural programming legacy all around the place, scripting nature that meant having to execute everything from scratch (even if cached) for every Request, slow execution and the need of caching literally everything to be able to achieve a good performance.
Prior to joining my current employer I've had lots of experience with Java for both Desktop and Web. I was a Certified Oracle Developer with OCPJP6 and OCEJWCD6 certs to prove it. PHP was, however, the central part of my day-to-day work. I was eager to abandon it and focus my career on Java. It seemed so much better. It had all the things I wanted to use and that PHP didn't have. Even though PHP in the early 2015 was already making much progress from the dark ages of its early, structural nature, I didn't want to wait any longer.
Now, after 7 years of pure Java development I know that, in most cases, grass isn't always greener. Don't get me wrong - Java is great and I love it, but it has its fair share of skeletons in the closet, like: long compilation and deployment time (looking at you, Spring), funky generics, primitives/boxing conundrum, extremely high verbosity and boilerplate, too many dependency managers and build tools - each with its own quirks, etc. The conclusion is - no language/platform is perfect.
So, maybe it's time to give PHP another shot? It's been, after all, almost 7 long years. When I was getting out of the PHP ecosystem, PHP 5.3 (the one that introduced namespaces) was my target platform (although many have already adopted more modern 5.4 - 5.6 versions - either by just upgrading the runtime or actually applying the new & cool features), Symfony 2.6 was my Framework of choice (with 3.0 being just around the corner). Now, in the last quarter of 2021 we have PHP 8.1 and Symfony 6.0. Both with innumerable improvements and new features.
Current State of PHP
PHP 8.1, compared to PHP 5.3 has (and I'm talking only about the most crucial differences):
- completely new interpreter with JIT
- up to 5 - 6 times faster (!) in synthetic tests
- up to 2-3 times faster in in web app response times
- Object Model enhancements like Traits, Enums, Constructor property promotion, read-only properties, Attributes (Annotations)
- Full Static Typing (apart from local vars) with intersection Types, union Types and syntax-embedded null safety
- Fibers (yup, co-routines are here)
- Closures, including first-class Callable syntax
Additionally, PHP ecosystem has:
- the best ever dependency manager - Composer (Maven and Gradle can really go to hell, in comparison)
- An absolute Developer Experience delight in the form of Symfony Framework - a thing that makes Spring Framework (which I love) look like a low level programming.
- Tons of running options, including:
- Roadrunner - Golang-backed server that makes PHP act almost like Java in regard to the load-once-run-multiple-times pattern
- uses Goroutines for lightning performance
- supports Go-written plug-ins for performance-heavy tasks
- ReactPHP - an event-loop based Framework with reactive Database support!
Sure, it still has the baggage of all the previous PHP versions, but it has to be much nicer now. Why won't I give it a try and see for myself?
The Result
And so I did. The effect is my 2-part Article about re-creating the original Symfony Demo, but with all of my present Architecture experience and knowledge. During its creation I was able to remember most of the PHP knowledge buried deep in my brain, but also to try the new & cool features.
What is my overall feeling after spending some time with the new PHP and Symfony? To my surprise - the balance between PHP and Java has shifted to a place when both technologies have comparable number of major strengths and weaknesses:
- PHP
- Development Experience is much nicer in PHP due to the speed of the feedback-loop driven by Automated Tests
- Java's Unit Tests, with all the needed compilation and build, can be slower than PHP's Integration Tests. PHP's Unit Tests give literally instantaneous feedback.
- That of course will depend on the PHP version used and on the Framework of choice. Web development in plain PHP is not very popular.
- Plain Java Web (Jakarta) is at least equally awful.
- There are some strong voices that promote using plain PHP due to PSRs being mature enough to be used on their own. While personally I'd choose a Framework every time, it's an interesting point of view.
- The time needed to deploy a PHP App (including Server Start) is an order of magnitude shorter than for a JVM-backed Application.
- Example: in the time window needed to boot a single instance of Spring-backed webapp you can possibly spin dozens, if not hundreds, of PHP-based Pods.
- Even though for a single instance, Java web app will still be considerably faster
than PHP, the majority of the world has shifted into the distributed
domain
- This makes PHP a better choice for systems that need to be dynamically throttled in real time. Provided that resources are not an issue, distributed PHP app may even provide better response times due to it being instantaneously up-scaled by the auto-scaler.
- Syntax, even though somewhat unusual and full of weird functions, is much less verbose and allows go get things done faster than in Java
- Kotlin fixes that immensely for the JVM
- Object model enhancements like Traits, Closures and 1st class Callable make creating Business Logic interesting and fun
- PHP libraries are not constrained by old, ridiculous APIs
- Doctrine ORM is much more convenient to use than Hibernate, due to the latter being pervasively used via the horrific, outdated and full of bad design choices JPA API.
- I don't hate Hibernate. It's pretty good on its own and its getting things done. But JPA, on the other hand, is a pile of old, not updated, atrocious, horrible APIs (Criteria API - I'm looking at you). Using Hibernate through JPA can be very painful.
- Java / JVM
- Raw performance (after warm-up) is still considerably better
- Ability to use stateful, managed resources
- Database Connection Pooling pretty much out of the box (in PHP its strongly db-driver dependent and generally not available, but should be more widely accessible via Roadrunner in the near future)
- True parallelism with Threads and Thread Pools
- Still much better Type System with Generics
- better IDE support for Java
- PHP Storm is great, but it cannot infer everything from the funky PHP's Type System
- Collections Framework with Streams support
- We can use Knapsack Collections in PHP for similar experience
Conclusion
PHP just another tool in the box. It does some things better than Java and falls short in other areas. It's modern and robust enough for developing enterprise-scale Applications. It has a great, thriving community, wonderful Tools and Frameworks (Composer, Packagist, Symfony, Laravel, Yii, Twig, Doctrine, Behat, ReactPHP, PHPUnit, PHPSpec to name only a few) and, over the past couple of years, has made huge progress in both performance and features.
It most certainly is not a tool that anyone should be ashamed of and doesn't deserve the still strong ridicule. The history of PHP is the one of the greatest redemption arcs in Software Development History. I wouldn't be surprised if, in couple of years, PHP will have much more cool features. There already are some great, actively discussed RFCs, like Operator Overloading, Sealed Classes, Algebraic Data Types or C#-style property accessors.
After all, if you'd tell the PHP community 7 years ago that PHP language will have all the features it has today, they would think that you're crazy.
this made me laugh
ReplyDeleteCare to elaborate?
DeleteTake a look at https://www.swoole.co.uk/, faster then reacthphp and has been around way before then fibers and as fast (faster then nodejs) as golang.
ReplyDeleteWow i have been around PHP for 5yrs now and am inspired by this article
ReplyDeleteTry PHP 8.1 with Laravel, you'll fall in love. Symfony is low-level compared to Laravel. :)
ReplyDeleteYou mean the Laravel build with symfony components? I don't know another Laravel but that...
DeleteSymfony is better
DeleteThat's true, Laravel is build with Symfony components, but that's not a bad thing. Laravel has much more features and much faster and better ORM build in. I've been using both for the last 3 years and can say that Laravel lately has improved so much that Symfony next to it seems like it is low-level.
DeleteThere is a duplication link in Roadrunner url
ReplyDeleteI recommend you also to explore the world of static analysis in PHP, with PHPStan and PSalm. It can be a game changing, for example adding Generics and other features compatible with PHPStorm.
ReplyDeleteHey, did u checkout static analysers like PsalmPhp or PhpStan, they make generics possible and other useful static typing (at least at compile time). Types is a "compile time concept" anyway.
ReplyDeleteExcellent information on you thanks you for taking the time to share with us. Amazing insight you have on this, it's nice to find a website that details so much information. Great blog. Web Development Company in USA
ReplyDeleteThanks for sharing this article here about the church book publishing services. Your article is very informative and I will share it with my other friends as the information is really very useful. Keep sharing your excellent work.
ReplyDeletedigital publishing services company
digital publishing services
Wow, amazing block structure! How long
ReplyDeleteHave you written a blog before? Working on a blog seems easy.
The overview of your website is pretty good, not to mention what it does.
In the content!
vstkey.com
PhpStorm Crack
ReplyDeleteI guess I am the only one who came here to share my very own experience. Guess what!? I am using my laptop for almost
the past 6 years, but I had no idea of solving some basic issues. I do not know how to
Download Cracked Pro Softwares But thankfully, I recently visited a website named Crack Software Free Download
All Pro Cracked Softwares Download
PhpStorm Crack
Wow, amazing block structure! How long
ReplyDeleteHave you written a blog before? Working on a blog seems easy.
The overview of your website is pretty good, not to mention what it does.
In the content!
vstpatch.net
FL Studio Crack
Waves 13 Complete Crack
FaBFilter Pro Crack
WebStorm Crack
Wondershare Filmora Crack
Interesting stuff to read. This blog regarding Columbus Web Design Company is truly helpful for me. Thank you for sharing such an informative blog with us.
ReplyDeleteExcellent Article, I just read and shared it to my friends as it is very useful for everyone. I will learn a lot of new stuff right from this article. You can check our services of ecommerce services provider in india
ReplyDeleteecommerce solutions
Great work with lots of knowledgeable information and thanks for sharing!!
ReplyDeleteJava Training in Pune
Java Training in Mumbai
Java Training in Kolkata
Hey friend, it is very well written article, thank you for the valuable and useful information you provide in this post. Keep up the good work! FYI, How to know if your dog is having a heat stroke , , ikigai book pdf download,essay on a visit to a hill station
ReplyDeleteAfter reading some blog posts on your site,
ReplyDeleteThank you for writing this blog.
We've added a list of bookmarks and will be back soon.
Also visit my website and tell us what you think.
Thank you for your work, thank you for sharing it.
Crackurl Full Version Softwares
Wondershare Filmora Crack
Nice post, Thanks for sharing this interesting blog, Are you looking for the best ? IT consulting services companies then choose the good company with good service.
ReplyDeleteIt is really a helpful blog to find some different source to add my knowledge.
ReplyDeleteWeb Development Testimonial
This is great post.I like this post.Many many thanks for this post.
ReplyDeleteRegards,
ProWeb365
This post will be weird for all of my usual readers. I'm a Lead Java Developer that's been writing about fun and clever things to do in Java ecosystem. What most of you probably don't know is that prior to working in Java,
ReplyDeleteI was a Lead PHP Developer for quite a while. Yup. The PHP. The language that is so divisive, that on one hand, drives more than 75% of the entire Internet and, on the other hand, is considered by many to be a pathetic, ugly scripting language, no better than universally hated JavaScript.
Steinco Industrial Solutions, Inc.
There is also Laravel which makes coding with PHP even more enjoyable.
ReplyDeleteI read this article, it is really informative one. Your way of writing and making things clear is very impressive. pls visit our website top 10 web development company in the usa
ReplyDeleteTry Quarkus. In developer mode you get hot reload and tests afffected by code changes are automatically run. You get faster feedback than with PHP. Use PHP for building monoliths Laravel with Livewire or InertiaJS or Symfony with Stimulus. But anything requiring a documented APIs other than CRUD should probably not be built using PHP.
ReplyDeleteThank you for sharing this informative blog about Laravel and developing web applications using it.
ReplyDeleteLaravel Framework Development
I am so grateful for your blog.Really thank you!
ReplyDeleteClient Reviews
Nice post!
ReplyDeleteYandex Browser Crack
Videoscribe Crack
Passport Photo Maker Crack
Heat Up Crack
Your writing has actually impressed me. i-Hidden Talent uses the latest and best technologies to provide the best service to its customers using HTML5, the latest JavaScript version, CSS3, EWS, Firebase, Mango database, etc. Web Development Company in USA
ReplyDeletePHP has updated with MVC and CMS frameworks that makes task easier and time saving. Kindly, check our platform https://www.essitco.com/ might amaze you more.
ReplyDeletePHP
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis post will be weird for all of my usual readers. I'm a Lead Java Developer that's been writing about fun and clever things to do in Java ecosystem. Website Consultant Service Provider Kuwai
ReplyDeleteI am happy that I found your post while searching for informative posts. It is really informative and quality of the content is extraordinary.
ReplyDeletewebsite development company
Very nice.
ReplyDeleteweb development
Very nice.
ReplyDeleteWebsite development
You are a best blogger I was read
ReplyDeleteI am thankful to you because your article is very helpful for me to carry on with my research in the same area. Your quoted examples are relevant to my research as well.
ReplyDeleteweb design columbus ohio
I love your post, and I always like to read quality content. You are describing one by one process; this post is easy to understand. I am also providing custom software solution services. If you are looking for Custom healthcare software development Company services in USA then visit our website.
ReplyDeleteThnks for sharing this blog with us . If anyone need good development company then visit healthcare app development company .
ReplyDeleteweb design Chicago is the creation of websites and pages to reflect a company’s brand and information and ensure a user friendly experience. Your blog is very useful to my personal use thanks for share this blog.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteGood Post!!! I like each and every aspects of your post and the incredible knowledge you share. Before reading these blog i dont have any idea about php framework but now I know many more things. Thanks to you.
ReplyDeletelaravel framework development
Unimaginably strong which you have shared here. I'm charmed by the nuances and besides it is a basic article for us. Continue to give such an information, Thank you.Local SEO Services
ReplyDelete
ReplyDeleteThank you for sharing this interesting post. manufacturing erp software india
I think wordpress is in php? It is why we get help from wordpress website support Australia coz we have a hard time with php
ReplyDeleteIt's nice to see that you're not afraid to try out something new! I enjoyed reading about it and am excited to read more about how it goes. Learn ASP.NET
ReplyDeleteWow, marvelous weblog layout! How lengthy have you been blogging for White Label Credit Repair? you made blogging glance easy. The overall look of your website is fantastic, as well as the content!
ReplyDeleteIt is really a helpful blog to find some different source to add my knowledge. software development company coimbatore
ReplyDeleteYour article provided me with some valuable knowledge. Please continue to write like this Nopcommerce Payment Plugin Development. Thank you for providing such useful information.
ReplyDeleteThis comment has been removed by the author.
ReplyDelete<a href="https://www.instaittech.com/services/nodejs-development/”>node JS Developer</a>
Deletenode js development
DeleteThanks for sharing a valuable information. Fita is best seo trainingcentre in chennai.
ReplyDeleteseo training
NICE BLOG
ReplyDeleteFIta.in
NICE BLOG
ReplyDeleteaws training
aws training
ReplyDeleteaws
ReplyDelete
ReplyDeleteThe post is really informative about Environmental Consulting Service USA and keeps posting and this is an Interesting Blog. Thanks for sharing.
Remarkable post, The information you have mentioned is really knowledgeable for website design toledo and engaging for us, I really enjoyed reading it. Thankful to you for sharing an article like this.
ReplyDeleteThanks for your post. It's very helpful post for us. I would like to thanks for sharing this article here. web design agency in bangalore
ReplyDeleteYour blog is really good. Are You Looking for website design and development company in melbourne? You can visit milestoneithub.com.au.
ReplyDeleteI read this article, it is really informative one. ITsoft is one of the best web development company in Melbourne. Our services include Web Development & top It support services. Top Web Development Company in Melbourne
ReplyDeleteCool!
DeleteThese are some of the great tips given for Java developer. The water softeners are good for clean and healthy water.
ReplyDelete