Image for post
Image for post
Lanzarote, Green Window in Sunshine, by Vlad Madejczyk

PHP or JavaScript headache

There are endless stories about why PHP is better than JavasScript or why only JavaScript — I mean JavaScript technologies like React, Angular etc, — should be used, and PHP should die, or will die next year. Few years ago I heard that PHP is dead (Node.js developers’ opinion), and this opinion pops up frequently. However, we have year 2020 and PHP is in much better shape than ever before.

I have used in my professional work mainly Assembler (ancient times), C++ (for 3d programming), ActionScript 3, Java, Node.js, Django/Python, and PHP CodeIgniter, Yii, Laravel, WordPress. Working long time as a freelance web developer taught me to be programming languages-agnostic. Mostly it is a company, your customers, which decides what technology you can use, because this is based on budget, and they don’t care what JavaScript can (or cannot) be better than PHP. Everything is possible, but ultimately what technologies you can use to deliver solution always depends on budget.

Let’s take simple scenario with an online bespoke Content Management Service (CMS). Why — for instance — not to use Amazon Web Services, set up an Ubuntu server and start with Laravel, if we go PHP route? Laravel is much better than WordPress, and WordPress is bad (well, some developers say that). This approach looks good, but it only looks that way. Laravel looks beautiful, but it comes with its, so to speak, not polite children:

  1. periodic not always backward compatible upgrades and
  2. unpredictable business dependency injections (like Tailwind CSS, and who knows what is coming in future, look at point 3).
  3. new stuff: Livewire vs Inertia.js, excellent, both excellent but WHY?

After your job is done, somebody, out there, in your customer’s company, has to take care about it, because CMS may (or may not) need maintenance, or some modifications and extensions from time to time. If the company has no IT department (well, because they hired you, a freelancer), it means that most probably Laravel is NOT an option, unless they can afford to have your services from time to time. Keep also in mind, that for most commercial projects Laravel cannot be used in shared hosting. I found that some companies offer Laravel hosting, but when you start using it, you will find that you need sudo permissions for some Composer stuff and — well — such cheap hosting becomes pretty much useless. In theory, you can use web hosting services like Digital Ocean, AWS or similar, and they are good and reliable, but again — somebody needs to take care about it after you deliver CMS. I found that every reliable Laravel hosting needs some server command line management skills and root/sudo permissions, and all this makes maintenance cumbersome for your customer. How many customers can afford such scenario? Well, some of them can, but not all of them.

You could use some JavaScript technology for CMS, but, if out there what you use is relational database, and there is nothing about chat or video chat, or some user interface updates in real time, using JavaScript technologies (back and front end) for CMS typically based on relational database would be overkill.

In fact, there are at least three things you should tick off before you start development:

  1. what is your budget (how much working hours you have at your disposal)
  2. what tools are the best for the job to be done (based on point 1)
  3. choosing the right tool look at technology, look at what features it delivers out of the box

If a project is about some SPA (Single Page Application), without need to save any data in database, or save it once only, JavaScript technology like Vue.js or REACT, or even Bootstrap/jQuery with Ajax or some typical front end stuff would be much better option than pure PHP with HTML/CSS.

And how about mixed scenario, where you need classic CMS functionality, but on top of that some pages here and there, with rather advanced business logic, and high level of user interface interaction, a typical SPA, which can be done on user side (internet browser) saving server resources? I would say: use Laravel, CodeIgniter, WordPress or something similar and a JavaScript library. You can develop SPA with PHP, no doubt about it, but at the same time you degrade user experience (UI) because of server connections/page reload. Degraded UI means worse performance on mobile devices and finally lower conversion, and business doesn’t like that.

Yet another example: advanced CMS with very complex module with much ML/AI and mathematical, statistical advanced stuff in the back end. Sounds like Django/Python with some JavaScript libraries here and there on front end.

What I described above is the tip of the iceberg. Anyway, I found that mixed solutions can be very often simpler, more time efficient, easier for maintenance, more cost effective than attempts to develop a project following narrow minded one-is-best-for-all approach. For instance: use WordPress, with cashing, as some kind of advertising (blog/posts) interface - as food for SEO and content eager users, where security is not a big issue - which can be updated by company employees, and create another module based on Laravel or other PHP MVC framework, with higher security level, for managing more important data. And make — if needed — both modules talk to each other via API.

Except that, web services developed in such way that they perform nicely also on mobile devices are welcomed — you cannot get easily this functionality with pure PHP.

In my opinion, if you compare different technologies, like for instance CMSs etc. or different programming languages, the most important thing is to find what they deliver out of the box. Not, what you can develop by using them, because ultimately you can build CMS also based on assembler. Look at a library, language, CMS to find what it delivers out of the box, what it delivers now, because developing missing features can be very painful.

For long time I have been not sure what is wrong with PHP vs JavaScript, until I realised that times changed. Code is poetry is long time gone. There is no time for code is poetry, it is a bait only. The pay better for delivery, not for poetry (unless converted into song and placed on top of Billboard’s The Hot 100 chart). What we have now is rather assembly line, a kind of 2 steps development:

  1. find what modules and/or technologies you need for your project
  2. make them working together, connect them seamlessly

Somebody somewhere have already developed and tested the bits you need for your project, so why to try to reinvent the wheel? Some PHP developers say that Laravel is much better than WordPress, and they are right, but also owners of WordPress websites, roughly 30% of all websites, where some of them make good money, are right too. It all depends. JavaScript developers say JavaScript is better than PHP and they are right, but — still — WordPress is based not only on JavaScript (it uses it heavily for good reasons) but mainly on PHP. So, PHP developers who say that PHP is better than JavaScript are right too. All this depends on context. Is CodeIgniter better than Laravel? Yes, it is. Is opposite true? Yes, it is. Without the context comparing most things doesn’t make much sense.

I develop in PHP, and “PHP is dead” Should I switch to JavaScript?

Just to give you an example: Cobol, a programming language designed in 1959, has been on a death bed for at least 30 years. It it is still not cold dead, it still delivers in many business companies, delivers reliably.

In my opinion there is a vaccine for the PHP or JavaScript sickness, and it is quite simple and cheap. If you are a back end PHP web developer, the best you can do is to keep what you already know, and learn at least one JavaScript library, like REACT, or Angular or Vue.js or something similar. This will change you into an augmented PHP developer, something like PHP^Vue.js. And this 20% upgrade of your skills, will solve you 80% of problems you face in your development. It will also solve one of the biggest issues in back end development: your work is basically not visible on front end, and customer’s private GitHub repositories where you keep your code must stay private — so, again your code is not visible. With back end stuff it is not always easy to create a portfolio, a showcase. PHP back end development has very poor visual side I would say.

There are things PHP can do in excellent way, but we have to face truth that there are things which JavaScript can do much better than PHP.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store