DEV Community

Cover image for I regret using PHP
Jorge Castro
Jorge Castro

Posted on • Updated on

I regret using PHP

I regret using PHP.

Right now, I finished a titanic project (around 3 year in the making) and the project is working as expected. However, it feels so fragile and I think I loss a lot of time in some other tasks rather than the own code (including testing/benchmarking libraries, creating our own libraries).

One of the key part of the project is the access to the database, so for this, I use an "orm". For PHP, you can use any ORM in PHP to do the job, however, this project is not easy and it requires some tricks.

First, I tried Laravel and the performance of Laravel (because I want to use its ORM) could be resumed in a single word: SLOW. So I rejected it completely. I tested other ORM and they are also really slow, so I created one from scratch with two goals:

a) simple
b) fast.

And here is the project

And it works (more or less).

Why do I need an ORM?

Because it is not possible to create a project using the primitive functionalities of PHP (PDO in this case), example:

Using PDO
(it is prone to mistakes)

$stmt = $pdo->prepare("SELECT * FROM myTable WHERE name = ?");
$result = $stmt->get_result();
while($row = $result->fetch_assoc()) {
Enter fullscreen mode Exit fullscreen mode

Using my library

    ->where("name = ?",[$_POST['name']]) 
Enter fullscreen mode Exit fullscreen mode

Using my library (ORM)

ProductRepo // this class was generated with echo $pdoOne()->generateCodeClass(['Product']);
    ::where("name = ?",[$_POST['name']])
Enter fullscreen mode Exit fullscreen mode

Then, I found the main problem of PHP: "dynamic typing".

dynamic typing

Let's say we have a function that returns a list of products.

Enter fullscreen mode Exit fullscreen mode

However, PHP does not know if we are returning a list of products. We could add type hinting, but (as its name says), it is just a type hinting/validation and nothing more. Type hinting is a cheap solution and it is not foolproof at all.

   function listall():array {
      // code goes here
Enter fullscreen mode Exit fullscreen mode

But, there is another problem. PHP doesn't have the concept of array-of-a-specific-type.

It is Java:

  products=new ArrayList<Product>();
Enter fullscreen mode Exit fullscreen mode

It is c#

  products=new List<Product>();
Enter fullscreen mode Exit fullscreen mode

And it is PHP

  $products=array(); // or simply [], so we could store an object, a number or whatever value here.
Enter fullscreen mode Exit fullscreen mode

objects versus array

Let's say we have a model of an invoice.

class InvoiceDetails {
   public $idInvoiceDetail;
   public $idInvoice;
   public $product;
   public $quantity;
class Invoice {
   public $idInvoice;
   public $customer;
   public $date;
   public $invoiceDetails;  // a list of invoicedetails
Enter fullscreen mode Exit fullscreen mode

What if we want to serialize:

   $invoice=new Invoice(); // $invoice is an instance of Invoice
   $json=json_encode($invoice); // $json is the class serialized
   $invoiceback=json_decode($json); // now $invoice is an instance of stdclass.
Enter fullscreen mode Exit fullscreen mode

We could convert it manually but it takes so much resources to have a correct serialization.

So, the best solution is to use an associative array. Why?

   $invoice=['idinvoice'=>1...]; // $invoice is an array
   $json=json_encode($invoice); // $json is the array serialized
   $invoiceback=json_decode($json,true); // now $invoice is an array.
Enter fullscreen mode Exit fullscreen mode

In PHP, we don't need to use models at all. We could use a bit of them to get some type hinting but again, it is not a perfect solution, neither it is foolproof or help in a big project. It also kills the performance considerably (mainly if you want to serialize/de-serialize).

Are libraries the solution?

There are some libraries to help solving those problems. However, they bring new problems: performance. Many PHP libraries use a lot of "hack" solutions to solve the problems of PHP such as serialization, for example using reflections and such. However, they are a minefield and some of them don't care about the performance at all.

But why I regret PHP?

Let's say our initial problem, a function that returns a list of products.

It is PHP

   // show the first product if any
   if($products!==null && count($products)>0) {
      echo $products[0]->name; // or $products[0]['name'] if array
Enter fullscreen mode Exit fullscreen mode

There is not warranty that this code will work because the PHP language does not really know that $products has a list of products.

It is c#

   List<Product> products=ProductoRepo.listAll();
   if(products!=null && products.Count()>0) {
Enter fullscreen mode Exit fullscreen mode

It will always works because c# knows that the variable products is a list of products (or null) and there is not other alternative.

And it is the implementation of the function in c#

function listAll() {
    var result=new List<Product>();
    using(var dbase=new BaseExample()) {
    return result;    
Enter fullscreen mode Exit fullscreen mode

It simple and it works. There is not minefield here.

It uses Entity Framework and it reads from the database, converts the value and returns a list of products. The performance hit is minimum (I tested). Why? First, the system does not need to guess the field (the field exists or it raises an error), it does not need to do type juggling and because C# is a compiled language.

And it is the serialization/de-serialization

string json = JsonSerializer.Serialize(products);
var productsdes = JsonSerializer.Deserialize<List<Product>>(json);
Enter fullscreen mode Exit fullscreen mode

And again simple and it works or it raises an error (there is not middle ground here).

For the records and about the comments

About Swoole

I tested Swoole and it works. However, it brings two problems:

a) It does not work on Windows.

You can't whine anything against Windows, but Windows is king for corporate and big companies. It means for example the office suite and other programs such vpn that only works in Windows. My Dev machine is and will be Windows because it works almost all programs (there are 3 exceptions, one of them is Swoole). ps: The second program that does not work in Windows is Docker. There is a version of Docker for Windows but it is a "tiny"-emulator, so it is not a true (lightweight) container but a bulky one (so it breaks the raisons d'Γͺtre of container)

b) Swoole is not magical. It is not a new PHP runtime engine on steroids, so if PHP is slow then Swoole too. i.e. Swoole works fine in one cases but bad in others. Also, I am not fancy to add more complexity to the code.

And for this case, C# allows async tasks natively, so we don't need to runs a separate service so we could multi-task those slow task in a separate thread (and without creating sockets). Microsoft warns us about when we should use it and when don't because multitasking is not a magic wand that works for every case.

Why I use PHP 5.x?

No, I don't. I use PHP 8.0.10. However, I can keep my code syntactically compatible with PHP 5.6 (at least the open source libraries). There are some new syntaxes in PHP 7 and 8 but most of them are syntax sugar, so it is not worth to migrate those public library from 5.6 to 7 or 8. Why?


However, there are a few useful functions but nothing else much. I like the opcache of PHP >7.0

Type hinting

One of the new features of PHP 7 is the type hinting and it is another minefield.


In PHP, type hinting is also type validation, and it is validated not once but every time the function is called.

// what you write
function example(Class $field1): string {

// what php really does:
function example($field1) {
    if(!get_type($gettype)!='Class') {
        throw new Exception("field incorrect");
    // ...    

Enter fullscreen mode Exit fullscreen mode

So it affects the performance. It is not a big deal in most of the code but some functions are called not once but thousand of times per request of the user. For example, if we have a function that takes 0.001 seconds but this function is called 100 times, then, in total it takes 0.1 second, so it is not so bad, but this measure is per request, so if we have 100 concurrent request, then we are taking 10 seconds in total. If we split in 4 cores, then each core is taking 2 seconds and it is not good.

Luckily, type hinting adds a mere 0.0001 seconds per 5000 requests, however it's easy to pile up slowness (example, 1000 concurrent users listing 5000 rows and each row calls 1 function)

I heavily use PHPDOC that it doesn't impact the performance and it is still more powerful than type hinting. It is not ideal but it is give some balance between performance and hinting.

Python in this aspect is more straightforward, In Python, type hinting is only that, a hint, not a validation, so its up to the code to validate the code.

C#: it does not need any of them because the validation is done at compile it, so it is evaluated once, versus PHP that it is evaluated for each call.

Psalm and PHPStan.

Both are nice libraries but again, they are not for free (they add a new "compile stage"). However, they don't do magic either, they are unable to detect all if not common problems while it forces us to work (for some tasks) in some very precise task.
But, I skip them because PHPStorm does many of the tasks of both without slowing the development process.


But again, both libraries are not even able to determine the right type of field of a variable (if the variable is enough complex).

About C#. C# has some libraries that do the same job. However, Visual Studio (not code) also do a superb detecting problems right out of the bat, but it also allows refactoring.

In general.

PHP is not a bad language. If you look at Python and Django (or Ruby and Rails), PHP is miles better but it is still trying to play a catching-up game with the big guys (Java and C#) then no.

PHP is playing a game of be a dynamic typed language while it tries to simulate a static typed language. Maybe PHP needs to forks itself and create a new static type language.

PHP and Impostor Syndrome

It is what I have seen

class Customer {
     private $id;
     private $name;
     public function setId(int $id) {
    public function getId():int {
        return $this-$id;
Enter fullscreen mode Exit fullscreen mode

What is the problem with it? The performance of this piece of code is awful. Java could work with this kind of code because Java optimizes the setter and getters. PHP doesn't have such feature.

And about Laravel, it is a model:

class Customer extends Models {

// O_O
Enter fullscreen mode Exit fullscreen mode

So we should guess the fields of customer. We could add some hinting and default values but nothing else much. Also, this model relies in some nasty reflection (__set method). Since Laravel is based in this of code and the model is the core of every functionality of the code, then it is the reason why it is slow.

And Symphony is not better, for example the use of YAML (it has some alternatives)

  actAs: [Timestampable]
  tableName: blog_article
      type: integer
      primary: true
      autoincrement: true
    title:   string(255)
    content: clob
Enter fullscreen mode Exit fullscreen mode

And Wordpress is not any better

Enter fullscreen mode Exit fullscreen mode

However, it gives the best performance and it is more straightforward. However, it will be hard to maintenance.

But why C


Of course, it does not show the whole picture, for example, servers that doesn't divulge the technology used.

Also, for employment in USA

  • python 176k jobs
  • java 142k jobs
  • javascript 119k jobs
  • c# 83k jobs
  • php 15k jobs

But again, it is just another measure that it is not complete. For example, Python is more popular than Java, but a Java developer lasts more in a job (the projects are more longest and well paid).

However, why PHP is the more popular (in public websites) and, at the same time, one of the least popular language (in jobs).


For the note:

Many developers have a mis-conception of performance and usability. Example: "my code is slow, however, if I add some framework or library, then it automatically will run better". Some libraries, specially frameworks, are not performance-wise. They are more focused in stability, validation and general use (and some of them are mainly syntax sugar over anything else).

In Laravel, it is what we do to assign a field:

Enter fullscreen mode Exit fullscreen mode

However, the framework does:

  • it validates if the field has mutators. If yes, then it applies it.
  • it validates if the field is date
  • it validates if the field is cast callable.
  • it validates if the field is json castable
  • it validates if the field is encrypt castable
  • and finally, it assigns the value to an inner array.

And when it validades if the field has mutators, it calls the method studly

    public static function studly($value)
        $key = $value;

        if (isset(static::$studlyCache[$key])) {
            return static::$studlyCache[$key];

        $value = ucwords(str_replace(['-', '_'], ' ', $value));

        return static::$studlyCache[$key] = str_replace(' ', '', $value);
Enter fullscreen mode Exit fullscreen mode

Every time.

What is the problem

for($i=0;$i<10000;$i++) {
   $object[$i]->field='hello'; // bye bye performance
Enter fullscreen mode Exit fullscreen mode

Discussion (72)

eduardoroblesch profile image

😲😲 My friend the problem is not PHP, the problem is YOU!!

I feel very identified with you when I started with PHP, I made a lot of mistakes. 😣😣😣

For small projects Laravel is fine, but if you have to develop a BIG project with a good logic domain in your entities, the ORM is Doctrine ❀❀❀. Doctrine is a mature ORM, and is a "data mapper" (Laravel ORM is an active record 🀒). Data mapper concept is SUPER intuitive (it feels like you have not a relational database, and instead you have a simple object storage). If you are familiar with Java, Doctrine is Hibernate for PHP!! With a data mapper ORM you are able to place the logic domain inside entities classes, unlike a active record ORM (Laravel), in an active record ORM your logic domain is everywhere except inside domain classes (entities) 😲😀.

You can use Doctrine as standalone library, but I also recommend you a framework: Symfony. Symfony use Doctrine by default (Symfony is Spring for PHP).

And about the problem of "typing lists", in Doctrine is perfectly solved with the normal "class typing" of PHP.

πŸ™„ And it is not all, if you think about performance, Doctrine has many layers: a easy and beautiful ORM, a native SQL, and even a batch processing to accomplish bulk inserts, updates and deletes.

leob profile image

Why can't there be domain logic in a Laravel model object? People do it all the time ... also I think Laravel's ORM gets way too much hate, undeservedly so ... if you want to go all out on DDD (domain driven development) or Hexagonal or whatever, you can do it in Laravel, if you want.

Yeah and frameworks like Swoole/Octane, combined with the newest (much more performant) PHP versions, with typing support, will go a long way towards addressing concerns about performance and (type) safety.

eduardoroblesch profile image

Yes, I'm completely agree. It wasn't "hate", I just wanted to say it in an emphatic and didactic way.

I love ❀ DDD and Hexagonal Architecture, I think it's cleaner working with a Data Mapper ORM, but Laravel it's ok.

johannestegner profile image

Worth to note is that you can quite easily swap laravels eloquent ORM for Doctrine, allowing you to make use of Laravel as an MVC framework while getting the power of a great ORM/DBAL.

eduardoroblesch profile image

Exactly! I agree.

micc1983 profile image
Alessandro Benoit

A few notes about your statements:

andreidascalu profile image
Andrei Dascalu

Looking for speed without type safety is a recipe for disaster. swoole brings the power of concurrency so your code and libraries better be ready.
Static analyzers are a patch that may or may not help as intended unless you hook them in your IDE and scan on save (which may be a pain depending on how many dependencies are required - if my file uses type X provided by a vendor which also uses interface Y, etc, I may need to load at least my vendors on each execution). Not to mention there's still no guarantee of safety at runtime (for arrays)

jacekandrzejewski profile image
Jacek Andrzejewski

If speed is an issue then that means code has problems and adding swoole won't really help as it will bring more problems. And if you read a bit through that pdo library, well, you will know that for sure.
Laravel and other libraries shouldn't be a big issue, unless you need responses in less than 20ms. Most projects I worked on returned responses in range of 50-80 ms without really trying to optimize things.

diguifi profile image
Diego Penha • Edited

Not trying to create a fuss or anything, but I have a few notes about your statements too:

  • Having a library to add functionality to a language, is a step that shouldn't exist in a language that's "good" by default (understand "good" as one that suits basic requirements of the context it's being used on).
  • PHP 7 vs ASP.NET Core is unfortunately a little worse overall (First PHP benchmark ranking 22nd while .NET ranking 8th)
  • Even on fortunes you can see a setup of ASP.NET Core ahead of PHP (aspcore-ado-pg vs php-ngx-pgsql), so no advantages for PHP in therms of speed, at all, compared to C#.

I don't think there's best or worse framework of any kind, they just suit different environments, BUT I believe that PHP shouldn't be used in large projects at all, enterprise level apps are not a good evironments for a language like PHP, small projects and portfolio websites are.

micc1983 profile image
Alessandro Benoit

Hello @diguifi , thanks for your reply. Unfortunately I know nothing about "enterprise level" apps (I mostly work on CRMs and custom apps for tourism and SMBs) so I really can't refute. Still, my point wasn't about PHP vs PICK_YOUR_LANGUAGE but more about specific statements made by the author that, as of today, make little sense.

andreidascalu profile image
Andrei Dascalu

you're confusing serialization with the default function provided by PHP. Serialization is the data representation that preserves the state of data for the purpose of data exchange between compatible system. PHP serialization, the native object representation, is one way to do it and it's definitely not the best.
The author specifies object serialization into JSON (json_encode). It's pretty clear: in PHP you can json_encode to string an object of class A and when you json_decode you don't get an object of class A anymore (you get stdClass, no other possibilities)!
Of course, I wouldn't expect that this would happen automagically (though plenty of stuff in/around PHP behaves automagically) but in all other languages you can specify what to deserialize into (complete with type checks).

juststevemcd profile image
Steve McDougall

This post feels very much like an attempt to get attention to a SQL query builder library build by the author more than anything.

PHP isn't the bad decision here, attempting to use a language you do not properly understand is the problem. Now I will be the first person to stand up and say PHP is wrong when it's wrong, but posts like this is just fishing for attention and is the problem with the developer community today.

You do not get cool points for dumping on PHP, you aren't going to become an influencer. You are however part of the problem. You're statement highlights your lack of respect for anyone but yourself, and you need to have a think about that before you post more.

To simplify, just in case you do not understand, stop gatekeeping languages and pointing your issues and inabilities at a language many professional developers are using more than effectively

ortonomy profile image
πŸ…–πŸ…‘πŸ…”πŸ…–πŸ…žπŸ…‘πŸ…¨ πŸ…žπŸ…‘πŸ…£πŸ…žπŸ…

Oh man. Nail on head. This entire site is thinly-disguised self promotion and propaganda. It’s not just, though. Everyone is into β€˜content marketing’ as it’s seen as the way to get exposure and β€˜move on up the dev food chain’. It’s gross - just write to be informative - the rest will come. Or just promote. It’s fine to do that too. Don’t give us this bullsh*t

gregholmes profile image
Greg Holmes

I'll be honest, I clicked the title knowing it was some form of clickbait. I wanted to see what they were going to say about PHP. Got bored before the intro was even finished knowing it was an advert for their own library.

Just wanted to comment that I completely agree with the two comments above

juststevemcd profile image
Steve McDougall

Someone else gets it!

anicetr profile image

"PHP is bad because it's not typed", thanks for your opinion.

Why not going with .Net core or something like that instead of pulling your hairs during 3 years with a language you're not comfortable with? I really don't get it.

eduardoroblesch profile image
EduardoRoblesCh • Edited

-- "PHP is not typed" 😑🀬😑
-- Mmm... Are you using PHP 4 in 2021?
-- Yes.


andreidascalu profile image
Andrei Dascalu

that's a pretty crappy way to counter-argue. To have typing in PHP you need:

  • declare(strict_types=1) - which works file by file!!!!
  • typehinting for both scalars and objects. In PHP 7.2 we got the (almost) across the board typehinting support when "object" was also added and in PHP 7.4 finally for class properties.

So yeah, PHP took its sweet time to get up to speed with how typing works. Sorry, not gonna blame anyone complaining. One reason PHP gets its deserved bad rep is that it build reasonable consistency across minor versions with breaking changes. Anyone who worked in any moderate scale project knows upgrades need planning and effort. It's easy to say just use a newer version but that's not always possible. There's PHP 5 still in the wild and people will judge PHP by what they see .

Thread Thread
eduardoroblesch profile image

Yes, I'm completely agree. It was a joke. πŸ˜„πŸ˜„

odahcam profile image
Luiz Machado

I couldn't even finish reading. The array-of-a-type concept is also know as generics and I think you have so much to learn before writing something like this.

dsentker profile image
Daniel Sentker

So you built a "titanic project" with a self made database framework? Congratulations, this is the reason you failed. It is not php.

Additionally, i assume that your project was an enterprise-sized one. Preferring Laravel over Symfony was the biggest failure then.

eduardoroblesch profile image

Next post: 🦴🦴 "Why I regret MySQL and How to Build your own Database System in C++".


blacksmoke26 profile image
Junaid Atari


ltsochevdev profile image

Nothing wrong with Laravel for enterprise development. I'd also like to know how the author figured Eloquent is slow? It allows quite the freedom, including writing your own SQL, so really it's up to the developer and not the implementation. Not to mention that instead of returning array of objects you could create a collection type class that only accepts specific objects and have that if you insist on IDE discoverability. It's sick how these rookies complain about non issues

vediansoft profile image
Tom van Tilburg • Edited

Start migrating to PHP 8 and enable strict. Treat it like a "real" language like C# or whatever and you have solved most of the issues before hand. PHP is a marvelous very strong serverside language if you actually know what you are doing (and it's only getting better ever since the release of >7.x.x and 8.x. PHP got shockingly popular ever since they released 7.2 and it's only growing). It is very easy to execute OS level commands, background processes and programs in PHP without having to make large adjustments or specialized applications for the OS. Trust me it's much more powerful than ruby is and ever will be.

Also, I'd like to point out that a lot of performance issues might come from the way you use switch statements in PHP. I'd benchmark those if I were you and see if you can improve and deal with it in a different logic.

I agree that PHP sucks if you do not treat it like a programming language or have to deal with projects developed by amateurs. But it's really good if the programmer treats it like any (what people call) "real" programming language.

Also instead of trying to make a PDO/ORM library/package yourself (which has been done many many many many times before and quite frankly a huge waste of time, that you got paid to do this really amazes me) use a library/ORM like doctrine and use only the things you actually need.

I'm pretty sure those 3 years, could've been 1,5 (and maybe even less) if you did not try to reinvent the wheel and analysed the project requirements and needs before starting developing it. The last statement is an assumption, but I recon I'm not far from the truth.

If you want a lot of flexibility, better performance and a good ORM out of the box, use symfony instead of Laravel (some cherry on top of the cake, is that symfony comes with a real nice formbuilder, so if you use it wisely you barely have to make any view files). If rapid development and quick results are required use Laravel. If you need a lot of performance, for say datastream processing, use objective c/c++/java or even serversided javascript. Like others said: the problem is not PHP, it's you.

ssmusoke profile image
Stephen Senkomago Musoke
  1. Building your own ORM for a project - recipe for disaster

  2. However "specialized" your project is, there is a need to leverage pre-built solutions that solve some of the base problems so that you can focus on the project business needs

  3. ORM Anti-pattern - everyone hates them as they are usually used badly, my decade old rebuttal which still makes sense today

martinaguilar profile image

PHP is one of the most used languages. If have to recreate the wheel, it because you probably are not going in the right direction. As is not the best practice try to do things like you would doit with other language.
PHP is simple, easy and fast. Runs everywhere and keeps evolving in a smooth way. Things that dotnet may not.

eduardoroblesch profile image
Comment marked as low quality/non-constructive by the community. View Code of Conduct

Next post: 🦴🦴 "Why I regret MySQL and How to Build your own Database System in C++".


strubloid profile image

I think that you wrote that years ago and now posted something old? Not typed? Did you at least Google it? You can start to use php7.4+(after that typing was there)

I really advice you to check Google before post something πŸ˜…πŸ‘

eduardoroblesch profile image
Comment marked as low quality/non-constructive by the community. View Code of Conduct

Next post: 🦴🦴 "Why I regret MySQL and How to Build your own Database System in C++".


jefrancomix profile image
JesΓΊs Franco

Come on Eduardo first time was fun but are you going to post it how many times more?

necross220 profile image
Obed David PΓ©rez Uri

Your regret comes from the preparation you had prior to start the protect, you are using pdo and json encode in the wrong way... As well as Laravel which is actually very fast connecting to the database... to be real what you are looking at is your skills on building apps without an programming/framework holding your hand, it's a common issue from people coming from Java and c# to languages like python, php or Lua...

ponsato profile image
JMTZ • Edited

First of all, I do not share anything from this article ... It is pure ignorance of PHP (developing in PHP is not equivalent to knowing PHP ... I play with C ++ and arduino, and I'm not saying that C ++ is bad and I I don't know how to do it right).
Use python3 and everything will go much slower than php5. Develop in node or react and you can gain in performance, but maintenance will be much more complex. Program in Net and you will get similar results. I don't understand the chase of php, I have yet to see a web technology that can "replace it with better performance and security results".

eduardoroblesch profile image
Comment marked as low quality/non-constructive by the community. View Code of Conduct

Next post: 🦴🦴 "Why I regret MySQL and How to Build your own Database System in C++".


ronxs profile image
RonXS • Edited

There's so many ways in using any programming or scripting language. I have a C and later on C# background, but love to develop in PHP ever since PHP4. It's rapid, it's easy and very fault tolerable.

The problems described above (where most of them are not entirely accurate), can be found in many languages.

Choices of frameworks, libraries is basically what drives us in our work. Weather to use or not to use a certain framework and what components you can use out of the box.

Doesnt matter if you use PDO, Doctrine or any other ORM. Same goes for Laravel, Laminas, Symfony or w/e. Most of these tools come with benefits and issues which you will learn overtime. Frontend developers often wonder what templating engine is best used and if you get enough people involved, the decisionmaking could be endless and would make for the best meeting discussions when it comes to "nerd levels".

When you go back to basics, you are trying to implement the same design patterns as you are used to in any other language (for example the commonly used Model View Controller) and use best practises for development like SOLID (

Using the 4th principle of SOLID called Interface Segregation already lays the foundation of a way which allows you to certainly have more control over the return type of a function, by using interfaces.

public function doTheThing(InterfaceA $myInterface) : InterfaceB {}
Enter fullscreen mode Exit fullscreen mode

About your serialization, you should take a look at JMS Serializer. I use it for all automated (de-)serialization. Here's an example which is identical to yours but in PHP:

$orderArray = $this->serializer->deserialize(
    'array<' . OrderDefinition::class . '>',
Enter fullscreen mode Exit fullscreen mode

All magic happens in type definitions (which can come from either a YML file with info, but i use @JMS Annotations personally.

ojrask profile image
Otto Rask

Thanks for sharing your experiences!

Starting 3 years ago would've provided you with a stable version of PHP (probably 7.2) that allows strict typing on method/function boundaries. If you picked an older version that doesn't support typing just as well (e.g. PHP 5 or older), you were already setting yourself up to fail.

PHP has no concept of generics, and probably never will unless the interpreter folks learn some magic. Generics can be emulated during development by leveraging static analysis tooling, such as PHPStan or Psalm. These provide you with the confidence to create "arrays of typed things" that are verified to work before runtime.

PHP objects can (in 99% of common cases) be serialized using serialize() and unserialize(), which prevents the issue you encountered, where your objects turn into arrays. Writing custom serialization logic is always an option as well.

PHP will of course be slower than nearly any other language that is compiled ahead of time, such as Java and C#. PHP is among the fastest on the interpreted languages market though, and allows for good performance if you want a faster feedback loop during development and shipping changes.

I really dig that you could spend the time to create a custom ORM, hopefully you had some fun and learned new things while doing so.

wlepinski profile image
William Lepinski

From your BIO: You are free to believe in whatever you want to, me too. So, stop preaching your religion, politics, or belief. Do you have facts? Then I will listen. Do you have a personal belief? Sorry but no.

Could you please elaborate why Laravel's ORM is Slow and why yours are much faster?

eduardoroblesch profile image

I guess his ORM is faster because doesn't has as many layer as Laravel's ORM, but... instead has hundreds of disadvantages.

turanmahmudov profile image
Turan Mahmudov

Hahaha. Using PHP as a 7 years old kid and still complaining.

jacekandrzejewski profile image
Jacek Andrzejewski

I worked in PHP for quite a some time and I haven't ever found any of the issues mentioned in the article.
I checked that library of yours, it's pretty obvious you don't follow PHP community at all. You don't know tools you use (phpunit), you don't use any of the modern techniques, you don't follow PSRs and have terrible code formatting and towers of ifs. Man, even more than 1/3 of files in this library has more than a thousand lines. You disable inspections in most of them. You use the silence operator which hides errors. All of the code is really hard to read, uses a ton of unnecessary calls and so on.
I inspected it with tools I use daily and found over few hundred "errors" (things considered by tools a really bad sign, not necessarily actual errors that break stuff). By the way, you talked about Laravel being slow, yet you use array_merge in loops which had a really huge performance hit in php pre 7 (and you allow for library to be used in 5.6). You even have always true if conditions.
No wonder it feels fragile. And it definitely is not simple. To be fair if this library looks this way then I'm sorry for anyone working on the project for which this library was written.

Please, check your code, your understanding and then say things like "laravel is slow" or "php bad" when you are sure it's their fault, not something you brought on yourself.

One thing: I know all of this may sound harsh, but that's not what I want to sound like. It's great you worked on those things, but it's easy to see this is not a language in which you feel good and it's not a language you know well. And that's ok.
If I find some free time I will probably try to improve your library a bit and send PRs, just to train.

sxshateri profile image
Shahin Shateri

Bro I'm pretty sure you need to understand the fundamentals of a programming language and keep yourself up to date with the changes and new features before assume a conclusion such as what you did.
If you don't know how to use the new features of PHP, it's not the programming language's fault but just yours.

ri5hirajp profile image
Rishiraj Purohit

I identified with the title because there are still somethings in java that I miss in php but after reading the post it seems more like you didn't implement/add few things that can solve your problems and stated that it's not possible.

Custom serializers, interfaces, instance of , get_type() and I would also first learn how to implement doctrine for faster queries, caching, using performant/specilized databases, before building my own orm because I cannot superceed years of hard work and learning by great developers.

The problems you are facing were there but now php is evolved into a great language with tools to help you avoid it's shortcomings. I suggest instead of blaming you ask on SO or Google , how to solve X problem and you will get ideas.

But kudos for building your own orm, your are on a journey to be a great developer. Also since the title is engaging and post received so many comments you are also a good writer. I understood completely what you meant, what you tried and how you solved it. Very well written.

ozzythegiant profile image
Oziel Perez • Edited

Agreeing with a lot of you here that this seems like clickbait for a custom PDO library. Laravel is fantastic for large projects but it certainly isn't the best option for everything (I'd recommend Slim if you want a more compact framework and to Bring Your Own Libraries). Query builders in my opinion are the way to go, so if you use ORMs, try to use direct query building rather than searching for data and then updating it. Less queries to run. Also, are you not indexing your databases? That's a must do if working with a lot of data! Lastly, also agree to using PHP 8 or at least 7.4. Processing times are much faster on these versions especially with JIT

chaladi profile image
Gopal Chaladi

Either you don't know PHP or just another PHP hater from .Net , java clan. PHP not typed??? Where are you living, in 2000's? Please don't write such articles if don't know with half baked knowledge.

dewofyouryouth_43 profile image
Jacob E. Shore

Then, I found the main problem of PHP: "dynamic typing".

So you were unaware of the issues dynamic typing in PHP until midway through a 3 year "Titanic" project!!?? πŸ€”

Anyways, I see you're getting a lot of hate from this article which is regrettable, so I won't pile on more than that. I haven't used PHP in a professional capacity since 2018, so I'm not really up to date with the latest.

This reminds me of a time when I worked on a project where the PO decided that we needed to home roll our own authentication system for an app. I learnt a lot about many interesting problems in the authentication space - but ultimately I think the company's time and resources would have been better spent.

But it's cool that you've made a new ORM and even cooler that you open sourced it

nkululekodube profile image
Nkululeko Dube

I think you using an old version of PHP. Also when you get time trying using Symfony πŸ™‚

ronaldaug profile image
ronaldaug • Edited

I also have some bad feeling about using PHP. Could some of you guide me?

  1. Some people say Laravel is the best PHP framework. But why don't I see some big company using Laravel? ( According to Googling )

  2. As PHP is a server side language, why Laravel does almost all frontend jobs, especially livewire?

  3. Why PHP copy almost all JS ES6 features to it? Like Arrow function, spread operator, destructuring Array, str_contains.

  4. Arrow function only allow single expression?

  5. Finally, is PHP still a worthwhile language to continue learning? According to stackshare, I don't see big company using PHP except Facebook, it was a decade ago.

ponsato profile image
JMTZ • Edited
  1. Find out better, laravel is even used to make the bed ... (all kinds of web applications). And where laravel does not reach, is symfony. This website itself looks like it was made in Laravel.

  2. Php is compatible with any front end system ... Literal, whatever you want. You can implement it in laravel and work with whatever you want.

  3. All web languages ​​tend to resemble each other in their syntax, be happy about this, it will cost you less to learn.

  4. Learn php 8, you're going to freak out. Arrow functions were not invented by ES6.

  5. Php is one of the most widely used languages ​​in the world (WordPress, Prestashop, Drupal, Moodle, Joomla...) practically more than 60% of the entire web is php, and it is still used ... I highly doubt that it will disappear in the next 20 years .. And with the appearance of php8 (currently the fastest and most secure web language by far), it will continue to be used in a massive way. The rest of the languages ​​may be a fad ... But php is established.

ronaldaug profile image

Thanks @ponsato , php8 looks great.

jefrancomix profile image
JesΓΊs Franco

This is the most elaborated rephrasing of the old motto of "you can't be fired for using IBM/Java/COBOL"

tavy315 profile image
Octavian Matei • Edited

5) 44644 companies reportedly use PHP in their tech stacks, including Facebook, Slack, and Lyft.

Take a look on stackshare.

ozankurt profile image
Ozan Kurt

That is a complete nonsense reasoning!

1- You wouldn’t need to write your own ORM if you knew how to optimize your queries.

2- PHP can now be strongly typed.

It’s just so lame of you to write a text like this and cry about your bad coding.

nake89 profile image
Kevin Kivi • Edited

I share your frustrations. I much prefer statically typed languages for this reason.
EDIT: PHP 8 seems great:
Looks like it would solve lots of frustrations. Probably PHP 7 does already a lot. Most of the PHP I had coded was years ago. And I have read many of the rebuttals in this comment section too.

blackcat_dev profile image
Sasa Blagojevic

I regret reading this

sirajulm profile image
Sirajul Muneer

I regret reading this article in!

hugosantiagobecerraadan profile image
Hugo S. Becerra AdΓ‘n

Sorry, but what I have seen in this article is a naive and misguided approach to PHP, libraries and tools.
Mixing async execution with multithresting? psalm or phpstan adds a new "compile stage"? What the heck that means? What about iterables, generics? ORM and DBA are the same? don't you know the difference?
Maybe fooled by the experience in other languages and trying to approach the same way and the same point of view. Many misconceptions I have found here about programming or languages in general makes me think when I started programming and fail under the same ways the author of this article did. Thanks to time and experience I have learned a lot of my mistakes, so I'm able to identify someone else who is at the same place I was so many years ago.
PHP was not your problem in this project, your approach and the lack of vision was.

derekzyl profile image

For me PHP was discouraged by many around so I couldn't explore. Funny enough it still has a large share of the internet. And guys that I know that uses PHP and are good in it do even the Impossibles with it. Fine it might be hard to learn said by many but when you know your onions it becomes piece of cake