404 points · by rakibtg · 7y ago · 360 comments
PHP files can be deployed independently, swapped out or updated live.
No building/compiling of the php files needed.
A single layer as opposed to 'modern architecture' where there's client side back/front end layers, api layer, logic, validator, data access, and ORM layers.
Can extend itself as it runs. For example Wordpress, running off of php files can download plugins to its own server (which are just more php files) to instantly extend itself. Without restarting or redeployment. (What other web platforms can do this?)
Intuitive, simple, powerful. Can be as easy as editing a php file in notepad and dropping it on a ftp server. Deployed.
Amazon lambda may have more in common with PHP in terms of discreet deployable units of functionality. What's old is new again.
Compiling/deploying an entire system to change a single endpoint feels backwards after using PHP.
Which becomes a security issue due to accidental endpoints or uploads becoming endpoints. Or becomes a mess of imports. Either way, PHP frameworks often end up with a central router anyway.
> PHP files can be deployed independently, swapped out or updated live.
Which means some people try to do that the naive way and end up breaking a few requests that happen during the deployment.
> Can be as easy as editing a php file in notepad and dropping it on a ftp server.
Which causes https://stackoverflow.com/search?q=headers+already+sent+bom&... because people don't realise they had an invisible character before all the code.
I really don't think any of those are a good thing.
https://news.ycombinator.com/item?id=2343351
It would have been possible for tumblr to avoid this with good development practices (don’t edit code live, don’t bake credentials into code, etc) but I imagine there was a culture of doing it at the time.
I don’t think it’s fair to tell developers “use our language, it’s super easy!” and then expect them to discard all of those bad habits as they start putting things in production.
In a complex product (as in, most professional settings or large services/web sites) the PHP I've seen is grossly complex, and not intuitive—especially WordPress deployments.
Dev teams have to perform all kinds of gymnastics with the PHP code to get it to do what they want, and it's just a flat out nightmare that I've made sure my boss and colleagues know that I have no desire to work with it.
It always ends up a house of cards and full of vulnerabilities so that something is regularly getting exposed that allows at least editorial access. Security issues that should otherwise be no problem.
God knows how many other vulnerabilities exist. Every single server I've ever had has had bots and crawlers polling for common PHP files in an effort to exploit them, should they exist.
I just don't like having even the chance that my back-end source could, for want of a single character, spill out to a web page upon request.
And then there's performance...
Anyway for simple things, sure. For things that don't require much security, sure. For anything else... it's not for me.
Yes, but the holes and gotchas are worse when they are baked into the language. The thing that Golang gets right, is that the developers are willing to eschew features to avoid gotchas. It's like other languages are sports cars with sexy lines and fancy features that everyone wants, but have to spend more time "in the shop." (An analogy for in the debugger.) Golang is more like a base model Toyota Corolla with a manual transmission.
Not sure what PHP is like. Maybe some sort of modder car. Like Perl and Ruby, PHP grew by readily adding features in response to demand. In that way, it's the opposite of Golang.
PHP is much less complex than most.
That depends on what level you're looking at. PHP is one of those languages that has a lot of complexity baked into it in the form of language design warts. In order to make it a nimble language, you have to ignore/eschew parts of it, and stick to some "good parts."
I'll be flask-ing
Non-atomic deployments? Not using Composer to manage dependencies? No separation of concerns? Editing files directly on the production environment?
I get that it's nice for beginners, but they're not benefits for professionals. We have better ways of doing things than Notepad and FTP.
PHP files can be swapped out live because many CGI wrappers don't cache anything in memory, which means at high strain you start dealing with disk load, file locks, etc.
There are many other languages which also don't require compilation, often at the trade off of less performance. Some really clever languages let compilation be an optional step.
A single layer means your frontend logic, data models, and database access all run the risk of being one giant mess. Sure other languages run that risk too, but it's especially prevalent in PHP.
PHP can extend itself - it can also be used to download attack vectors and execute them directly on the server with no concept of code signing. Other languages offer powerful facilities for remote updates if they're desired, but that's usually not the best approach for Web.
You can edit other languages with notepad too.
Being able to deploy a single endpoint to a live server and hoping it doesn't cause problems sounds like terror.
www.example.com/widgets.php
can be reached at: www.example.com/widgets
But here's the kicker: www.examples.com/widgets/123
will also route to widgets.php, with "/123" in the $_SERVER['PATH_INFO']. No mod_rewrite needed. www.example.com/widgets/you/can/have/multi-segment/paths
goes to widgets.php too, with its PATH_INFO set to "/you/can/have/multi-segment/paths", but I don't usually go that far. Usually the script name roughly corresponds to the name of a table (or database view), and the PATH_INFO corresponds to the primary key.[1] https://www.vdoo.com/blog/vdoo-discovers-significant-vulnera...
1. It doesn't sound like they were using MultiViews at all but some rewrite rule that rerouted all requests ending in .srv to a shell script in /bin. This isn't how MultiViews works. The file must exist, and it must be in the document root. A request to /foo won't work unless /foo.php (or foo.html, etc.) exists.
2. This rerouting was supposed to happen only for admins, but the authorization failed, due to a different bug, CVE-2018-10661.
3. The attack then depended on a bug in dbus, CVE-2018-10662
4. Finally it depended on a third flaw, CVE-2018-10660, having to do with shell-script injection.
So I don't think any of this should scare away a person from using MultiViews for .php scripts, which makes setting up clean, maintainable routes easier than any other technique I've seen.
Sometimes I'm in the middle of messing with the Lovecraftian horror that is the modern JS stack or screwing with extracting what I need from whatever awful request object someone cooked up or any number of other things that aren't accomplishing anything of business value and I wonder whether maybe somewhere we veered way in the wrong direction, as an industry.
On the more general point, I am not sure scripting languages lend themselves better to lamdbas, as dependencies are usually external to the system. For instance PHP often relies on system json/xml libraries. Database access also needs to be precompiled and installed on the system, as would be crypto or internalionalization routines.
Compared to that, I'd expect compiled runtimes can have one single "fat" binary that has most of the risky dependencies and only rely on the bare minimum provided by the system.
The vast majority of PHP frameworks, even micro-frameworks, don't work that way. They route all traffic (except static assets) to an `index.php`, which then forwards it to a regular router.
Perhaps end-users should not have the capacity to so easily add third party PHP code, even if it’s “simple.”
But that plugin system also is one of WordPress' greatest assets. And you can add PHP code to any part of a "theme" too. If you turned off the ability for themes and plugins to be "added live" then I don't think WordPress would be nearly as successful as it has become.
Wordpress is not PHP.
And I think you can definitely argue that a low barrier to entry means that it gives beginners a lot of power they don't quite understand.
Which is why I think most people steer towards common web frameworks, because not many people can know all the ways you can create security issues.
Then you get into the complexities of various common web frameworks (Zend, etc) and you have to really wonder if the original OPs argument about simplicity and ease-of-use are worth that trade-off from using something else.
Since it's basically just doing eval(loadFile(...)), any language with eval() can do this, for better or worse. Which is like most of them. Perl, Python, Ruby, and Lua, to name the most common.
> Intuitive, simple, powerful. Can be as easy as editing a php file in notepad and dropping it on a ftp server. Deployed.
This isn't really php specific, with cgi you can do that in any language, even compiled ones like c.
> Amazon lambda may have more in common with PHP in terms of discreet deployable units of functionality. What's old is new again.
Agreed. I must admit I'm guilty of this myself, there is a tendency to start with a framework when there are much simpler and quicker ways to get started, something the world seems to have largely forgotten.
Java: Use a classloader to load a JAR and instantiate one of its classes: https://stackoverflow.com/questions/60764/how-should-i-load-...
.Net - use an AppDomain (or other methods): https://stackoverflow.com/questions/1137781/correct-way-to-l...
I mean that's just how CGI works, most every HTTP server still supports CGI, nothing stops you from deploying that way. Unless you're using Java or the like of course, then it's not very convenient.
I mean, it's insane and you shouldn't, but it's eminently possible.
Try to deploy any self-hosted service like nextcloud, gitea. It was a nightmare to deploy nextcloud. Also it turned to be too slow for ONE USER.
php app/console cache:clear --env=prod --no-debug
php app/console assetic:dump
php app/console cache:warmup --env=prod --no-debug
chown -R apache:apache . # fix owner
chmod -R u=rwx,g=rwx,o=rx app/cache # fix cache perms
apachectl restart # bounce Apache, otherwise it can throw segfaultsNot if you're using... literally any modern framework and deploying it properly. This hasn't been the case in years except for common legacy stuff like Wordpress.
I'm quite sure you can achieve this in golang with plugins[1]. That not as flexable as PHP, mainly because it involves a static type system and a compile phase (and more work in general).
I think what this demonstrates is that Go isn't a better PHP. Rather, we're at the point where Go could be used to build a better PHP. The most likely paths for this, are to somehow come up with a big group of developers with a penchant for doing this, and/or have some big company fund this.
This doesn’t seem to be a language choice problem, it seems to be a monolith problem, where PHP simply managed to avoid some of the traditional monolith issues by design. Your CD pipelines in any micro service architecture should solve these problems, whether it’s using FaaS or containers, or whether it’s using a compiled language or an interpreted one.
No - it didn't. PHP up to this day is a spaghetti mess it had always been.
Except in reality once you want to use non /whatever/file.php as urls - you're back to implementing a router
> PHP files can be deployed independently, swapped out or updated live. Intuitive, simple, powerful. Can be as easy as editing a php file in notepad and dropping it on a ftp server. Deployed.
Except in reality, you don't want to deploy directly after editing a file since it's like deploying to production, you're gonna have a bad time.
> A single layer as opposed to 'modern architecture' where there's client side back/front end layers, api layer, logic, validator, data access, and ORM layers.
Except in reality, that just leads to a bunch of spaghetti code with no separation of concerns and impossible to maintain.
> Can extend itself as it runs. For example Wordpress, running off of php files can download plugins to its own server (which are just more php files) to instantly extend itself. Without restarting or redeployment. (What other web platforms can do this?)
Except in reality, this only works with php apps that have an integrated package manager and even then it leads to problems when a version is incompatible both in php or plugin dependency.
> Amazon lambda may have more in common with PHP in terms of discreet deployable units of functionality. What's old is new again.
Except in reality, serverless lambda is a terrible idea:
1. lock in to a specific platform with limited visibility tools and a dependency on a 3rd party when shit doesn't work
2. when functions change you run into function incompatibility chaos and no smart way to handle that mess
3. the "scalability" win is a lie, it's just deferred to whatever data storage service you are using - which ends up blowing up because while serverless scales, the db doesn't
4. addendum to 3, the statelessness of lambda means you can not use local caches to increase your throughput - increasing your hardware requirement
> Compiling/deploying an entire system to change a single endpoint feels backwards after using PHP.
Except in reality, you are notified of a bunch of potential bugs right there and then, instead of "maybe" finding out about them at runtime especially since PHP will by default consider a non defined variable just an empty string and display it as such on the page, and it's not until Joe User notices it that you'd ever find out.
The logging analysis tools are excellent and it’s quite easy to tie your lambda logging to whatever tool you are using.
As far as “lock-in”, there is an Amazon provided framework in every supported language to just add a proxy that allows you to use your standard framework (Node/Express C#/ASP.Net, etc) and you cab deploy to Lambda or your traditional web server with no code changes.
2. when functions change you run into function incompatibility chaos and no smart way to handle that mess
What???
3. the "scalability" win is a lie, it's just deferred to whatever data storage service you are using - which ends up blowing up because while serverless scales, the db doesn't
Serverless Aurora (Mysql) and DynamoDB both have autoscaling. You can also auto scale Read Replicas fast with traditional Aurora.
4. addendum to 3, the statelessness of lambda means you can not use local caches to increase your throughput - increasing your hardware requirement
Again not true, if you are calling an endpoint frequently, the instance stays warm for up to around 15 minutes and can maintain state.
Also since the release of PHP 7.0, core development seems to have really picked up with good stuff in every release (7.3 was just released a few months ago).
The only thing Laravel had going for it was that you could take more shortcuts, and it was a pain to integrate into any IDE if you wanted decent autocompletion.
It's still a horrible abomination of a language that invites bugs and requires A LOT of care to not produce buggy code, though.
Configuring a service to monitor gunicorn, which itself took a bit to configure, before I begin configuring NGINX or Apache... it's really a pain in the butt.
LAMP/LEMP stacks just... are
LEPP (nginx, PostgreSQL, Python) stack seems to me an all-around better stack for most of the deployments people use LAMP for.
Deploying is as simple as touching a reload.wsgi file.
Turns out, leveraging Dokku and having the right files, ie a Procfile to bind your app to Gunicorn and pushing the repo to the dokku instance was all it took.
Granted, it's for internal use so downtime isn't that big of an issue.
Granted, we're talking about largely server side generated web pages and, haha, who does THAT still in 2019 : hangs head in shame :
But I am rewriting my personal site/blog in Go as a trial run/learning process. I've been critical of Go in the past so I thought I'd give it a... go.
So far I don't mind the experience. No server framework, either. The standard library is actually pretty good, at least for something simple like that.
The only [external] dependency I'm pulling in so far is `blackfriday` for parsing Markdown files (the posts) upon request— I'm much too lazy to write a Markdown parser myself for this purpose.
It's not finished yet, but it's on its way— https://github.com/robertfairley/rf-19-go
Citation needed. I’ve had a very nice time. It’s statically typed, has excellent templating support, and is generally very productive.
I'm glad it's working out for you, but I don't think it's a stretch to say it wasn't really designed for it. On its own, that doesn't mean it's a bad fit; but I agree with your parent and think it's awful for this type of stuff.
(1) - https://commandcenter.blogspot.com/2012/06/less-is-exponenti...
Credentials: Worked mainly in go for 4 years... 18+ years coding in about 9 languages.
Yes I realized this is opinion.
MySQLd in PHP is a mirror process, and in fact retains the C function names.
Or anything else for that matter, maybe aside from some command line tooling.
Facebook goes into this category then, I presume?
The community seems bent on the whole "all you need is net/http", but that just isn't practical in modern web development. People like ORMs, easy to handle html forms, security as a default, easy session/cookie handling etc. In the end, web developers want ease of life.
Go is a great language for many things, but if it's going to take on the web at large (outside of HTTP APIs), the community needs to grow out of this "net/http or nothing" approach.
There is some hope, some frameworks like https://gobuffalo.io/en are showing up, but the Go ecosystem is dying for a Rails/Django solution.
People always use this modern term as if it implies something significantly different or more "advanced". The web hasn't changed much. It's still data over tcp sockets to a contained runtime -- a web browser.
> People like ORMs
People in my experience are starting to dislike ORMs. If you have done this for long enough, you realize they are great for getting off the ground, but they inevitably get in your way, and start generating some really bad queries which you have to start one by one replacing with raw SQL statements, at which point you might have well started with raw SQL.
Having come from Rails, and PHP frameworks like Symphony and Laravel at my company, using Go I feel almost like I am more intimate with my code. I understand it better, the dependency chain only ever goes one or at most two levels deep. I will admit the the templating and routing is more "batteries included" in these frameworks, but the other parts that I have control of that I consider much more important (such as how my data actually gets stored and other network calls I have to make), I would much rather do those in Go than in PHP
I greatly miss the nice, clean ORM experience. It's so much better for developer efficiency.
That's what I see around me as well.
I use go for building websites and it was the first time web development really made any sense. All the other systems out there require tons of tools, and lock you into doing things their way.
So, what makes GO so much of a pain? Maybe ignorance is bliss for me?
Nothing is stopping you from writing everything yourself in any other language. You can do the same in Java or .NET. Then you start finding out you need routing, validation, security, DB access, etc. which golang lacks and ends up making it much more verbose than other mature frameworks.
Still did it in go because it was a very simple webapp and deployment is so easy with go, but for a more complex task I'm not sure I'd have used it.
Trying both Laravel and Symfony I think there is no need for Laravel (anymore). Laravel just has too much magic that will bite you later on.
The only thing you should skip in both frameworks are 'annotations'. But this is easy to do.
Especially when that is not explained in the docs or just in a very vague way...
I tried improving the docs by pointing out where magic (e.g. fix naming conventions) is needed and where not, but the mantainer just turned that into vague mush again (after he had even agreed to the changes).
Also if you need any more details that are not in the docs, everyone points you to paid video courses that assume you have a Mac...
That honestly leaves me with a bad taste im my mouth after trying laravel :/
I don’t know. It’s odd.
I assume you're referring to laracasts.com... what does having a mac have to do with the videos there?
A controller should not know about routes.
A model should not know about database design.
For me Laravel was a nightmare to use with Vue. Both template engines (blade, vue) use moustache tags so everything has to be declared inside @vetbatim. Then mix doesn't even compare to ease of vue cli imo. Then the nested directory structure was so confusing (was it inside resource folder, or controller folder). I've never been happier since I ditched these opinionated frameworks
Routing
Templating
DB abstraction
With both PHP and JS this isn’t the case, which is why you see SO many frameworks for them: all of the parts are already there so the frameworks are mostly just rearranging things. Ruby, Python, Go, etc are general purpose so the frameworks provide a lot more support.
PHP’s biggest hang up for years was lack of name spacing for good module support so EVERY framework had their own version of every core feature you’d need abstracted around its framework naming schema. Can you imagine every framework writing their own database drivers...because that was happening.
As soon as Composer was released it was only going to be a matter of time before the ecosystem started to clean itself up from 9 different ways to install shared code.
Glad to see it’s happening.
Additionally, the PSR project has standardized a lot of APIs (HTTP request/response, logging, cache to name a few), which means if a package conforms to PSR, you get interop out of the box and can quickly swap implementations if needed.
composer require guzzlehttp/guzzle
Now you have GuzzleHttp available to your app. This way you include only what is needed. new Vue({ delimiters: ['${', '}']...If you are using Doctrine the only alternative to docblock annotations is XML because they are deprecating YAML support. I really hope they build support in the language itself. I can't understand their fierce opposition to a feature every other major object oriented language has. They are only forcing a large part of the ecosystem, everything that is Symfony or Doctrine based, to use the horrible docblock work around.
If you have that much time to spend on rewrites, I really envy you :-)
> They were a little surprised to hear our stack involved Golang and some flat out told us they’d prefer PHP, because that’s what most of our products rely upon.
I believe this is the real reason why, and everything else above it is pointless technical justification for a sound business decision. I also believe there's an unvoiced, even more powerful reason, in "I already know PHP and don't want to learn a whole new thing."
These are both sound reasons. The technical justifications are not.
Choosing Go for something like this was a bad decision. But choosing PHP is only slightly better. Opting for Django, Rails, or Phoenix would have better technical justification, but technical justification is rarely the real reason why we make decisions like these.
I think that if they choose to use a high-quality, modern php framework like Symfony, the technical decision would still make sense in the context of the alternatives you mentioned.
This isn't just technical; its baked deep into the culture of Go. And that's fine. Its designed for something different.
Check out Sylius for a really solid Symfony based application: https://sylius.com/
I came to Go from mainly C++, Java, and Python background, and I feel like it's the best of all 3 (to me). It's compiled and really fast (like C++), it has a great set of libraries and community interaction/support (like Java), and it has simple syntax that is clear and quick to understand (like Python).
It's not a perfect language (nothing can ever be), but it's become my favorite to use for back-end web services and even taken over some of my scripting workflow.
I can see it being painful if you're trying to render websites server-side though. That's a bit outside of what it's made for
Writing code-generators for everything wasn't fun.
I wish we could use more than channels - for me, I often feel like I'm shoehorning them in because there's no support for protected objects (native queues, conditional variables etc).
Perhaps I'm just using them wrong. Sometimes I have to use locks, and I don't think we should be forced to use locks in 2019. We've had better solutions since the 80s.
Absolutely not. Locks/spinlocks are found in pretty much every significantly parallel software project. It is pretty arrogant to criticize almost all software architectures on earth.
Use https://github.com/kisielk/errcheck for that.
Or prefer https://staticcheck.io/ for a larger set of checks.
Go is actually simpler than PHP as a language, once one understands "explicit" pointers (though PHP does expose pointers for a few things, arrays for instance since they are copied by default).
As for PHP, it's useful IN SPITE of itself, and that's the issue, the language works against the developer and only the tooling, frameworks and rigorous security practices can mitigate its flaws.
The whole integration in composer with the symfony flex component makes developing even easier than before: https://symfony.com/doc/current/setup/flex.html
“Just for fun, I compared apples and oranges again by benchmarking the login page (which doesn't hit any database) for both application versions using Siege.
The Symfony application (PHP 7.3, OPcache enabled, optimized autoloader) handles about 1470 req/s. The Go application (compiled using Go v1.11) averages about 18600 req/s.”
> it’s more maintainable for us to do it in PHP right now
If you're at that scale then probably symfony isn't for you.
You're not alone mind you, most of the new platforms are not very popular just because of how embedded WordPress is in its ecosystem. It just surprises me that both WordPress never moved on and that the PHP developer community never chose something different when it was clear WordPress had no intention of moving to more modern practices.
It was the only CMS I could find that had the level of simplicity I needed.
Imho the best CMS for PHP.
What are the amazing option do you suggests with batteries include in the language would be ideal.
Comparing Go ans PHP a few years ago would mean to compare Go and PHP/Apache or PHP/Nginx, because PHP could not run its own server.
It's like comparing Git and Subversion, where you have to explain concepts like staging.
Or IntelliJ and Eclipse, where you have to explain workspaces.
All talk of accessibility and ease for new users often comes off as posturing by some tech folks who then proceed to rubbish any efforts at achieving it and the compromises involved. It fits in nicely with the 'contempt culture' recently covered here.
The growing problem for the technical community and new users is the marketing by other languages, frameworks and those vested in these ecosystems which means using forums like this to belittle, rubbish and exaggerate any perceived fault in everything else. PHP's contemporaries like Python, Ruby, Javascript have their many downsides too but these efforts create false binary narratives. This is not a good basis for technical decisions or informed discussion.
I have a lot of discussions with friends in the startup scene about the topic of Laravel vs Symfony. So far it's a head to head race.
I have yet to find a good 'Laravel vs Symfony' comparison page. Yes, there are tons of 'SEO optimized articles' with this title. But I find them all rather uninformative and often even totally wrong and unfair.
The page I would love to see would have the same project coded twice. Once with each framework. And then display each file on the left for Laravel and the corresponding file on the right for Symfony.
But there are multiple reasons I choose Symfony 4 over Laravel.
And if you want a code comparison then this small example:
Laravel:
class User
{
}
Symfony: class User
{
private $id;
private $name;
public function getId():?int
{
return $this->id;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getName():?string
{
return $this->name;
}
}
Laravel looks a lot easier and quicker. And it is.
But good luck next month when you can't remember what properties User has. Your IDE can't autocomplete it. And also good luck working with a team. Your team members have to look up the database model for the User to see what properties are available.And this is happening in Laravel all the time. Very quick, very easy, a lot of magic but it will bite you in the end.
You could also hint these with / @var */ there are ways around it but yes it isn't ideal. I really liked doctrine, perhaps I was using it wrong, but having everything in annotations was pretty nice since migrations etc could run off of it.
With doctrine I ran into issues with performance, which you can alleviate with extra lazy etc, it also hydrated what appeared to be massive objects, which you had to use a custom debugger because print_r'ing one with the recursive references etc caused some crazy issues. I have since moved on from PHP, but if the project calls for it, I have no problem using laravel. While not ideal, it sure is productive to build an API in. I wrote a project in lumen, which is/was a subset of laravel built for APIs, and that was okay to work in. No clue if it still exists.
There’s curl-multi[0] you can use for that purpose. Not as nice as promises/async/await, but it gets the job done for your example.
[0] https://secure.php.net/manual/en/function.curl-multi-exec.ph...
So you can respond to websocket messages or http requests asynchronously but you're not going to be able to implement anything like a parallel merge sort were you offload work to other threads. Things like general purpose file IO are not easy at the moment either.
Amphp might seem a heavy handed because they've taken the monorepo approach. ReactPHP on the other hand has broken everything up into individual components. For example, you can get started with ReactPHP by just pulling in the event loop https://github.com/reactphp/event-loop. All the heavy lifting for the native loop is <200 lines https://github.com/reactphp/event-loop/blob/master/src/Strea... and the API is tiny as well https://github.com/reactphp/event-loop/blob/master/src/LoopI...
PHP 7.0 took a huge step forward by straight up removing old extensions that weren't maintained, focused a lot on performance and allowing more strict standards, and tons of new improvements. In addition, more modern frameworks like Symfony and Laravel started to pop up, which helped reduce the stigma of it just being a "scripting" language and made it very pleasant to work with.
I maintain a PHP app that was originally written in PHP 4, and one that was created in PHP 7 and the difference is night and day. I maintain a few Ruby and Python apps as well, but even having used these more often PHP still tends to be my go to for prototyping.
PHP's gotchas are syntactic/semantic but mostly on its huge standard library, which is an haphazard collection of functions from sending emails to parsing ID3 tags from MP3 files.
EDIT: JS, as the legend says, was written in 10 days, while PHP grew without much long term vision for years.
This rant is almost seven years old now, but I imagine that some things still hold true.
Python in particular is indisputably more versatile than PHP.
PHP was one of my first languages, and it took a long time to break some bad habits it taught. I still can't get over the existence of PHP's "arrays." (Mentioned in the article.) The only data structure is one-size-fits-all. It's truly baffling when you approach it with basic CS knowledge, and the rabbit hole only gets worse...
However, let's prove once more that languages evolve: http://php.net/manual/en/book.ds.php
The "classic" you're referring to is far from something objective. There will always be problems with languages. That's why we have the human factor who is supposed to be intelligent and work around the apparent issues and make the computer do useful work despite apparent tool glitches.
Sadly, we're just creating better idiots who are only getting better at whining.
Someone wrote an article with a title like "php a language with terrible design" that got traction.
I like the language and with the right framework and templating engine its a pleasure. (I'm moving code from silex to symfony).
I've been to a fair number php meetups and frankly people there seem to be end result focused not so concerned with the language. 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.
Funny, that is React/JSX's biggest sell
E.g., I've seen a payment management suite that was written using php traits, which then had a super class that everything descended from, meaning every service could do everything, completely breaking OOP. For example, a DirectDebitService has methods like processMandate(), processDd(), but then because of the traits it also has access to processCreditCardPayment(). As you can imagine this made unit testing literally anything require lines of set up code and just made things impossible to work with.
With the introduction of classes, and PHP 7's scalar type declarations as actual keywords rather than just PHP docs, as well as the option for strict comparison, plus the ridiculous speed improvement between 5.6 and 7.0.
Further, tools like composer (which I think was actually one of the first modern package managers (with lock files, version selectors), Behat for integration tests, plus the huge steps frameworks have made in removing in overhead have made PHP actually a very nice language to write these days.
Deployment in a micro service context is still annoying as PHP's built in web server is not great, requiring you to have an Ngninx pointing at a PHP-FPM which actually serves each of your microservices.
You may think you can get away with one Ngninx, but then as soon as micro services start requiring things like scaling it's a pain in the arse. E.g. you may wish to do rate limiting or rbac or something for a specific service, requiring an nginx->PHP-FPM in front of each PHP service.
I'm sure there are cleverer ways to get around this but this is the way I always go and the way I've seen other PHP deva go
The entry level language gets the reputation of the code written on the platform.
That's why basic, flash, php, Java, and JavaScript all had bad reputations at one time.
You can knock on any sufficiently complex language, it's actually really easy.
Python, for instance, gives different numerical results between 2 and 3 for the code "False - 3 * True / True / 2 + 3 * False" (-1 and -1.5)
Making things look absurd isn't hard.
I wonder which part is performance unmatched?
My opinion would be Crystal language for its simplicity and higher throughput but unmatched performance is behind Rust and C.
That, or it can be read as "in the family of web-friendly languages". The only other "fast" language widely used for the web is Java.
It's pretty good with Python too, which we have a little bit of (mostly Flask apps).
I like the batteries included standard library and single binary deployment of Go.
PHP, like others have said, gives you a single endpoint and you can make rapid changes. Its ideal for internal web apps that do not require insane performance.
And there alternatives. The best known is probably Revel: https://revel.github.io
For a doctrine (ORM) alternative you have for example https://github.com/jinzhu/gorm
The point about Go; using those types of tools is generally frowned upon in the community. It's overkill for most (micro)services.
But few gophers build a full-stack website in a single application.
I'm a gopher; I wouldn't want to use Revel or Gorm. I feel I'd be using the wrong tool for the job. I'd more likely use Django or Symfony when I'd need to build a full-stack SSR.
If a backend API is used by different clients (mobile apps, SPA, servers, ...) using a full-stack SSR framework like Symfony or Django doesn't make much sense anymore. You wouldn't use 90% of the framework's features. It feels like bloat.
But many websites don't need to serve different clients.
The author's decision to go from Golang to PHP makes perfect sense if he's building SSR websites.
I'm getting old ;)
Obviously things will have matured since then.
Doctrine implements the Unit of Work pattern. From what you're saying GORM is more like an Active Record ORM.
You're right, that wouldn't make it a good direct alternative.
> find . -name "*.php" -print0 | xargs -0 -n1 -P8 php -l | grep -v "No syntax errors detected"
Other potentially useful tools:
- PHP_CodeSniffer (https://github.com/squizlabs/PHP_CodeSniffer)
- GrumPHP (https://github.com/phpro/grumphp)
- PHP Mess Detector (https://phpmd.org/)
The speed advantage of HHVM has also been largely erased. Some high-profile PHP sites migrated to HHVM before and up to ~2015, but I haven't heard of a single site doing that since PHP 7.0 came out.
How is Go any different?
Meanwhile, I can't think of any major online service that relies on Hack apart from Facebook and its subsidiaries.
I could go on a very long discussion about why I prefer Rails but at the end of day it's just up to you to compare.
When I started Rails I was building an app with Symfony, took me a week to get it to a good state and it was extra frustrating (I had been doing PHP for 5 years).
I started Rails, learned Ruby on Wikipedia and just general googling and got the same app in a few hours.
This has nothing to do with homomorphic encryption, unless I'm missing something.
composer require some/library
That's PHP's package management. What's so non-trivial about that?Unlike some other package managers...
Deadlocks and race conditions.
For node, the entire app is a single thread so this just doesn't happen. For python/php/ruby concurrency is abstracted away and handled above the framework layer so the programmer never has to deal with it. You can launch threads in a route handler for these languages but it's not often done and you have nothing like a context object that is basically this abstraction leak that explicitly forces the programmer to constantly be aware of concurrency issues.
After some years of development, both languages have evolved a lot and they both can be used for many other things, that they haven't been designed for.
PHP was a dynamically typed scripting language to build personal homepages (Personal Home Page Tools). Today it is an object oriented, type hinted language that supports functional and object oriented programming, many database management systems and has a package manager (composer). I really like PHP (see https://github.com/sandreas/m4b-tool for a proof), but some concerns about PHP have always been (and still are):
- backwards compatibility reaching too far
- way too big standard library (see levenshtein function)
- the "callable" concept - call_user_func_array([$obj, "method"])
- mixing up too many concepts (OOP, Traits, Functional style)
- the type system (which is getting better with php 7)
- unpredictable statements - empty($x), comparisons (== vs ===) and the "mixed" type
- the "array" type being array and dictionary and...
- the $ used for variable declaration
- $this-> is still needed for calling object methods
- "." for concatenation and "\" for namespace separation
Another bad thing about PHP is, that on most web servers it is meant to be stateless, which means that you are in trouble using technologies like websockets.
Some of these things unfortunately mean that PHP often is much slower than it could be - and this is where "go" can be a successor. Performance. If you really need FAST web apps and performance is the goal, go can be a nice choice. But for getting things done in a not too complex web page, i would always choose php.
For at nearly 10 years now PHP has had support for lambdas, meaning for most uses `$foo()` can be used instead and with the inclusion of the spread operator it's seldom used.
[$obj, "methodName"] => callable for $obj->methodName()
"str_replace" => callable for function "str_replace"
["ClassName", "staticMethod"] => callable for ClassName::staticMethod()
"ClassName::staticMethod" => callable for ClassName::staticMethod()
function() {} => callable for a lambda
I would prefer a "ClassMethod" and a "Function" type, instead of using strings.
$x = phpinfo; $x();
$y = $obj->method; $y();
But i don't think, this is possible, because PHP supports global constants and function names cannot be distinguished from constants, especially because PHP is not case sensitive regarding functions and classnames.
But I see, that my karma has decreased with this post, so it seems, that not many are in my opinion...
The above list is just an indeed subjective list of things i don't like about PHP, although i like PHP in general and it is NOT a PHP rant!