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

 

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.

Comments

  1. Take 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.

    ReplyDelete
  2. Wow i have been around PHP for 5yrs now and am inspired by this article

    ReplyDelete
  3. Try PHP 8.1 with Laravel, you'll fall in love. Symfony is low-level compared to Laravel. :)

    ReplyDelete
    Replies
    1. You mean the Laravel build with symfony components? I don't know another Laravel but that...

      Delete
    2. That'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.

      Delete
  4. There is a duplication link in Roadrunner url

    ReplyDelete
  5. I 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.

    ReplyDelete
  6. Hey, 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.

    ReplyDelete
  7. Excellent 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

    ReplyDelete
  8. Thanks 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.
    digital publishing services company

    digital publishing services

    ReplyDelete
  9. Hello, Thanks for sharing nice blog with us. this is really very nice blog again to all thanks i am regular reader your website

    Custom Software Development near me

    ReplyDelete
  10. Wow, amazing block structure! How long
    Have 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

    ReplyDelete

  11. I 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

    ReplyDelete
  12. Wow, amazing block structure! How long
    Have 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

    ReplyDelete
  13. 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.

    ReplyDelete
  14. Excellent 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

    ecommerce solutions

    ReplyDelete
  15. Great work with lots of knowledgeable information and thanks for sharing!!
    Java Training in Pune
    Java Training in Mumbai
    Java Training in Kolkata

    ReplyDelete
  16. 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

    ReplyDelete
  17. After reading some blog posts on your site,
    Thank 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

    ReplyDelete
  18. 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.

    ReplyDelete
  19. It is really a helpful blog to find some different source to add my knowledge.
    Web Development Testimonial

    ReplyDelete
  20. This is great post.I like this post.Many many thanks for this post.
    Regards,
    ProWeb365

    ReplyDelete
  21. 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.

    Steinco Industrial Solutions, Inc.

    ReplyDelete
  22. There is also Laravel which makes coding with PHP even more enjoyable.

    ReplyDelete
  23. I 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

    ReplyDelete
  24. Try 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.

    ReplyDelete
  25. Thank you for sharing this informative blog about Laravel and developing web applications using it.
    Laravel Framework Development

    ReplyDelete
  26. 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

    ReplyDelete
  27. PHP 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.

    ReplyDelete
  28. This comment has been removed by the author.

    ReplyDelete
  29. 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. Website Consultant Service Provider Kuwai

    ReplyDelete

Post a Comment