Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

> it is actually designed with that in mind.

One of the gripes that I -and many- have is that PHP wasn't ever "designed" in the first place.

This is changing. Has changed. But for people, like me, who started with PHP back in the 3.x days, and left in the 5.x days, PHP has a bad history. It might overcome this, or already have. But the history sticks to it.

And it begs the question: why make PHP into a new Python, or Ruby or JS, if we already have a Python or Ruby or JS (or Typescript)? Because if any language is actually designed (for a broad sense of that term) for the Web, it is JavaScript.



sort by: page size:

> Why?

PHP was designed from the start to be a web-first language that solved the issues people had using Perl as a server-side scripting language. I think experiencing the pain points people were having trying to repurposed other languages for the web lead to a lot of good* design decisions.

* Good, in the sense of ease of use.

It also didn't really give you many options in the beginning: everyone just used the LAMP stack and made it work. You could use Windows or Postgres, but you just didn't without a compelling reason.

Nobody today wants to design a single-purpose language that locks users into a platform. Users don't want to learn a single-purpose language and be locked into a platform.


> So, if you are looking for good design in a language — PHP is still a disaster, I assure you.

PHP is like an unholy blend of Python and JavaScript with Perl syntax rules. If there's some feature you like in one of these languages, PHP probably has a slightly-confusing variant of it.

It has first-class function support (more-or-less), closures, classic OO, dynamic OO, reflection, namespaces, exceptions, auto-resolution of missing classes, generators, iterators, something like eval(), etc.


> And finally, PHP is written expressly for the web, not like Java, Python, Ruby or whatever the latest fad is these days - where web stuff was bolted on instead of baked in the design and operations of the language.

I don't think this matters at all.

Python and Rubi in particular have much better constructs for web development than PHP could ever get (because of its lack of state mainly).

"Bolting" things on top of a general purpose language is exactly what those languages are designed to enable.

In my view, PHP's main feature is that it enables an smooth transition from static pages to fully dynamic ones. That's responsible for a lot of its popularity, but is not a good feature to consider when starting a new project.


> It started clumsy, true, but it became a solid and quite elegant way of doing things.

No. Just no. PHP will not be solid and elegant by evolution. It might have become an excellent tool for the area it's supposed to be used in, but the only way it could ever become elegant is if it had its python2=>python3 sort of moment. They would need to break it to fix it.

I don't think they'll do that, since I think they understand that it doesn't matter at all that the language sucks.


> pick a random language, ruby, python, javascript etc etc and you'll find similar rants/complaints

Yes, but that's not the point - the primary trait of "old PHP" (I don't know the "new PHP") is that it has not been designed.

Languages like Ruby, Python, etc. may have been designed, in a better or worse way, but there's a radical difference with a language that hasn't been designed at all.


> why would anyone want to start something new with PHP in 2021?

What can you make in X language than I can't make in PHP? And vice versa?

Don't get me wrong, I fully support the "select the right tool for the job", there are obviously better languages and frameworks for different kind of tasks, but let's just consider the context in what PHP is usually used in.

I get that people dislike a syntax. I loathe Python, basically because indentation actually controls how and whether your software works and I can't use indentation for organizing the readability of my code.

But that doesn't mean that I would ever argue against the use of Python; again - what can you make in Python that I can't make in PHP? And the other way around still.

inb4 "But PHP doesn't do async" - [fibers](https://wiki.php.net/rfc/fibers) is a start on that journey. We've managed so far.


> PHP wasn't "designed" ... it evolved. Pieces were added, here and there, re-factored, deprecated, etc. etc.

We are all aware of that. We don't like that. Not because of its genesis, but because of the result of that process.

> PHP is a natural language. It wasn't fabricated at some university, nor in the lab of some billion dollar company. It evolved.

> That is its strength. It is the most adaptable language around. It can be used for anything and it has been used for everything.

You have to purposefully design a language that can't be "used for everything". And boy, the way PHP has "adapted" could be done by any language or designer or committee if they were just to lower their standards enough. But most haven't, and have adapted with more success. Why did PHP barely get (half-assed) closures just now?

> And that is why it is the most popular programming language.

Where?

(Though I think IHBT)


> PHP has matured and has been a nice language for a decade now.

And how did it manage that? Python forced people to deal with encodings properly and the result was a lot of pain. You're claiming PHP somehow invisibly fixed the numerous problems of the language without anybody noticing? That "fractal of bad design" blog post, everything described in it has been fixed?

If so I want to learn how they did it. That's some heavy duty language evolution work.


>I've always had this dream of writing something like "PyHP"

Similar here, Something Ruby-PHP. But even PyHP will do for me.

I think the problem is PHP was designed by someone who just want to get shit done and absolutely dreaded programming. Versus programmers who just wanted to create a beautiful programming language.


> I think it also is due to the fact that PHP is a fairly easy language for a non-coder to pick up little-by-little. One can easily start using it for doing simple things, like injecting dynamic data into a web page. From there one can learn to scale up to full web apps.

I personally started using PHP because, at the time, the free hosting servers only had support for it. Otherwise, I could probably have picked python, ruby (or even perl). I wasn't a non-coder, but I think that these languages may be self-taught with the same ease as PHP (well, maybe not perl).

> In my 20 years of writing code (starting with PHP) I have learned the lesson over and over again that while writing code commercially the fact that the language has feature X or that it forces certain patterns means almost nothing. Sure, your developers might feel better about themselves but that is about it.

But, isn't that the whole point of using PHP 7.4 over, say, PHP 3 (besides evaluation speed)? Would you code in PHP 3 today, if PHP had not evolved at all?


> modern PHP is a fine language.

I am sorry, but bolting on a ton of 'modern' features on a broken language does not make it not-broken. If it does anything, it is to put up an appearance of being modern, while remaining rotten on the inside, and hence all the more dangerous.

Remember, the most broken aspect of the language is also reason for it's very defining feature (No or very little learning required to get started). Hence one cannot hope that PHP will be fixed at some point in the future. Because fixing the language thus will actually involve killing it and designing it from the ground up, at which point you can just use Python 3.

And that is even considering that the PHP community is competent enough to identify the flaws of the language. But I think what happens inevitably is that, people who can really see how broken the language also see the hopelessness of the situation and immediately switch to something else or use it only to pay their bills.

If you think I am not familer with modern PHP, here is a tool I wrote some time back in php, for php programmers to deal with the pain of working with namespaces and also provide intelligent auto completion for editors like vim..

https://bitbucket.org/sras/cliche


> Most of the criticism of php seems to contrast it with a language plus a framework. If you really want to compare, compare php with ruby or python, not Django or RoR.

Why? What difference does that make as a programmer using it? If another language is more modular, and lets libraries handle things that are baked into php, isn't that a good thing?

> As for php encouraging shitty programming, a good bit of that is that so many more people program in php because its easier to get started with. This does not mean that just because php attracts shitty programmers that it doesn't have more or many awesome programmers than languages such as python.

Maybe not, but it makes it harder to hire the good ones.


> and the availability of web tools is much wider in php than for python.

If that was a metric for language quality, then Javascript would be undeniably the most perfect language ever designed by any intelligent species in the universe, judging by the number of frameworks.

> to an almost decent language

And now I would like to hear a good reason why I should use an "almost decent language", when I can use a decent one instead.

> It can be used properly if you know what you are doing

It doesn't matter what I do, the language still insists of having multiple modes of error handling, a massive amount of builtins all of which sit in my global namespace, it's configuration is still seperated between compiler flags, a system wide ini, and local config. The base deployment mode is still "dump files into folder and let CGI do the rest".


> I don't think there's a good reason to design a language specifically for web projects. If that's how PHP works these days (I haven't used PHP in a decade or so), I'd suggest that might be a bad thing. It's very rigid, and if the language gets anything wrong that compromises the design of every project that uses it. Languages should provide simple primitives that frameworks and libraries build on.

That has always been the goal of PHP, to be a web framework in itself (and now we have frameworks on top of that framework). It's trivial to read POST data as understanding POST requests are built-in into the language. With Rust or JavaScript you either will pull down a external library to handle that for you, or write a ton of code to make it easier for yourself. With PHP, it's literally one-line of code.

It is not as rigid as you might believe, as we have frameworks on top of the native PHP framework already. That's not to say PHP is without compromises, it's not suitable for a bunch of different projects (you wouldn't write mobile/desktop apps with it for example). But if you have a simple CRUD application that just needs to output some HTML data and persist stuff to a MariaDB/MySQL database without wanting to pull down a bunch of 3rd-party dependencies, PHP will make that effortless compared to basically any other language.

I think the popularity of PHP for web development speaks for itself, it basically conquered that segment of development when it first appeared, and is still more-or-less king, even with its warts.

As a last word, I like that languages specializes in different things, not every language has to be a general-use language, and I hope we see more of that in the future. Darklang specializes in building backend APIs for example, others specializes in being for UIs and so on. As every language more or less looks like C today, there is plenty of room for innovation in programming language design (and no, not talking about TypeScript which is basically just C# that compiles to JavaScript, but more different languages).


> “ I prefer to use languages in the domains they were designed for”

So for web development, do you use PHP?

Because neither Python, nor Ruby nor even JavaScript itself was designed for web development.


> I wish PHP could start changing in a "let's redesign it" way.

I think that's foolish. Redesigning a language is making a new language -- and there are lots of other new languages to choose from. What features of PHP would you want to keep that aren't possible in other languages?

Radically changing the language also leads to heavily splitting the community like with PHP4/PHP5 or Perl5/Perl6 or Python2/Python3 and nobody wants that. Backwards compatibility doesn't have to be fully maintained but it does have to be respected.

The biggest issue right now with PHP is that there isn't a clear direction on where to go. Nobody wants to "fix" some of the old problems because the gains don't seem to outweigh the costs.


> what's wrong with PHP?

There is a great deal of complexity on every single construct on the language, and there is not enough expressive power to create simple programs that do a lot of things.

At the late 90's and early 00's, there was a fashion of creating high level languages by adding very powerful framework into a very basic language. That makes for a beginner-only language that is easy to kinda-learn, but hard to create anything good. PHP is trying to evolve beyond this, but all the legacy does hold it back.


> When I write Javascript or Python, I have complaints and issues, but I enjoy writing code. I think PHP, for many programmers, including myself, is just a hostile and unenjoyable experience.

Surely JS has at least an equal amount of foot-guns to PHP. I mean, at least PHP (to my knowledge) never had a meta-language written around it that compiles to PHP to make it safer.


> Frankly I think PHP doesn't have as strong a fan club as ruby/python, which are decent languages but they too come with their own quirks.

The reason quite possibly is that those are joy to use where PHP isn't. In my mind the developer happiness should be on top of the list, also the syntax is still ugly however you look at it. The versatility of Python is unmatched. Ruby allows me to do things I could only dream of in other languages, in PHP those dreams are nightmares.

next

Legal | privacy