It is one of the best choices (if not the best choice) for rapid prototyping of a program. Its damn fast to similar alternatives (Python, Ruby, Dart, JavaScript), and the standard library is huge.
It does have footguns. I am not a fan of the loose typing, but you can take some steps to mitigate. You can do "===", "strict_types" and type hinting for function input and output. It is similar to C in that the language itself doesnt really do much to stop you from writing bad code. Also the function naming is not consistent, and even function arguments are not consistent. However PHP 8 will help with that somewhat, as you can now do named arguments.
Also PHP has the best language documentation I have ever seen. I would prefer more examples, but its well above some other languages.
PHP is basically a wrapper of C modules.
String functions are ($haystack,$needle)
Array functions are ($needle, $haystack)
Because that's the way the underlying modules worked. I had used PHP for a long time without realizing this.
https://wiki.php.net/rfc/string_to_number_comparison https://wiki.php.net/rfc/saner-numeric-strings
In addition more internal functions throw exceptions instead of notice+return false on completly invalid arguments:
Other than that, PHP is rock solid when it comes to web stuff.
I keep hearing about how the language has improved, but to me it feels like even if the language gets rid of all its heaps of crap, it still is in a evolutionary dead-end. Is there anything that PHP is developing or adopting that can not be had at other established languages?
(Edit: I never had something downvoted so fast before. This is not concern trolling. I seriously would like to know if it makes sense for a non-PHP developer to look into it)
Modern cryptography is baked in since 7.2.
https://libsodium.gitbook.io/doc/bindings_for_other_language...
Most of the people who shit on PHP have a lot of love for other languages. A survey of the cryptography features the "favored" languages offer will almost certainly fall into two camps:
1. "We wrap OpenSSL"
2. "Go compile it yourself" (i.e. there is nothing baked in)
There's a lot of badness with OpenSSL's API design, especially with asymmetric cryptography. For a fun exercise in these languages, try encrypting with RSA with OAEP padding, but without using SHA1 as your hash function.
For completeness, PHP is one of the languages that wraps OpenSSL too! But it also wraps libsodium, and the community has been moving towards libsodium (unless they need something from OpenSSL for the sake of backwards compatibility) since early in the 7.x series.
If you're going to provide cryptography features in your language, but you aren't shipping modern cryptography in your standard library, you're underperforming what PHP has offered for years at this point. The easiest way to meet the standard that PHP 7.2+ establishes is to add libsodium to your language's standard library.
(There are salient arguments for "why even provide a cryptography feature as part of the language at all?" but most of the languages that see real world deployment are already doing that.)
PHP 5 was released 16 years ago and was a massive evolution of the language. The same is true for PHP 5.2, 5.3, and 7. It's safe to say that your conclusions about the language are no longer accurate.
> Is there anything that PHP is developing or adopting that can not be had at other established languages?
No. I can't think of any reason to start a new project with PHP today. All of its best features are things that have been available in other languages for years. It's also not particularly popular outside of WordPress.
I know of no other language that lets you deploy a web app by dragging some files from the left to the right in FileZilla. No setup, No vendor lock in, no nothing. It just works.
Cross-cloud serverless frameworks that wrap AWS lambda + competitors get you somewhat close in other languages, but you still have a lot more setup to go through, and lot fewer hosting providers to choose from.
PHP's deployment and execution models really set it apart.
No, not really, but it's still very good for casual web development, which makes up the lion's share of all backend code being written today.
Languages don't need to evolve a ton to be popular – just look at Python, which is doing very well despite not having had a ton of radical changes.
IMO, no. The language is still near the bottom for both dynamic and "static" typed languages. HOWEVER, if you're doing web backend stuff, Laravel and Symfony are both really solid frameworks.
The direction PHP Is moving in right now is to emulate Java 7, but without generics or concurrency. It's definitely a dead-end unless they come up with something pretty novel and change direction (again).
I think for the vast majority of projects, this is not a question you'll be asking yourself when picking the language.
I think PHP is one of the best languages to pick when you want a quick MVP for an online service (one that doesn't require specific things PHP is not good at). The community is one of the largest, there are more developers than nearly any other backend language and Laravel is probably the most complete all-in-one backend framework out there.
So the question is often, is PHP good enough to develop a maintainable app with decent performance, where developers won't hate every minute spent on it. And the answer is pretty much yes with PHP 7+
One thing that PHP does better than any other language for web development is ease of deployment. It isn't really anything inherent in the language that makes it easier to deploy, it's simply that hundreds, probably thousands of web hosts have made deployment easy for PHP. Also, the PHP community has documented deployment and installation scenarios thoroughly.
Deployment might sound like a small piece in the overall picture of building a web app but it is actually hugely important. If you want your users to self-install your web app, or to give them the widest possibly choice of deployment hosts, then PHP beats every other language by a mile.
I always mention this quote from blogger and programmer Jeff Attwood on this topic of depolyment:
"If you want to produce free-as-in-whatever code that runs on virtually every server in the world with zero friction or configuration hassles, PHP is damn near your only option." [1]
Guess when he wrote it? 2012.
Sure, we've got VPS and even more hosting options, but in 2020 what other languages can match or even surpass PHP's ease of deployment? Can you give instructions to your relatively non-tech users and tell them how to successful deploy your web app with the same ease as PHP?
I feel like I can ask that question about most established languages and get the same answer back. It still has the easiest deployment and development flow of any language I've ever used. I don't know of a single language that does that right now, and makes going from 0 to 100% much easier, which for smaller pet projects, it's so much less hassle. Upload file, it's running on the web. That's it.
As for all the features it has that other languages have, PHP tends to merge them together. While this means the language is larger than most, it also means I can do things in ways I want to and try new features out.
This doesn't mean I'm not using JS or Go or Java or other languages. But if I'm building a web API, PHP is the one that gets out of my way and lets me build it quickly and easily.
Good documentation and reasonable backwards compatibility.
Probably not, but that's the wrong question. The real question is: If you already know PHP, is there enough incentive/benefit to switching languages? Based on the experience of PHP devs I know (I personally haven't used it in years), the answer is "no" for many (most?) web dev cases.
I would say no, but of course, the same is true of most other established languages. What's interesting about PHP is that it's shifting from being a dumpster fire that you would never pick over a real language like Python/Ruby/node/Java/whatever, to one that's honestly broadly comparable for many tasks.
Is it innovating or doing anything really unique? Well, no, but you don't tend to find much innovation or unique features in any of those languages (these days, anyhow). At best they copy them (eventually) from the innovative languages. :)
> I seriously would like to know if it makes sense for a non-PHP developer to look into it
No more or less so than any other big, mainstream, relatively popular language. Learn it because you need it for a job, or because you'd like to see how another language ecosystem solves common problems. Don't learn it thinking you're going to see anything especially new.
It's a decent language and with frameworks like Laravel you can quickly build reliable CRUD apps, which is the vast majority of websites and development.
I'm coming from an academic background and i was looking to learn a new backend language to create simple CRUD type, web applications. I already know c/c++, java, js and some python but after research it seems that Rails, Laravel and Django are the best options for this kind of projects as javascript on the backend is still a mess. So i've made a little comparison between them to choose what to learn.
Rails: It might be the best full stack web development framework from what i'm gathering, but it's declining fast and Ruby has a small market share outside the US.
Django: It's been always the 2nd or 3rd best option. Django 3.0 is going async which looks great on paper but in reality it needs work. It doesn't have a built-in asset pipeline for modern js development on the front-end. It needs plugins for basic stuff like social, api auth etc. Python has libraries for almost everything but the web is not always a first class citizen.
PHP: It is by far the most popular backend language. Libraries are tailored for web development and are probably well maintained because they are used by huge projects(wordpress, magento etc). For the same reason it won't disappear any time soon because it handles most of the information on the web and also billions of dollars in online commerce. Symfony has the most contributors than any backend framework and Laravel is probably the easiest framework to create an MVP with. Developers love Laravel and the community is huge. PHP is also improving and adopting new language features with a more advanced type system.
So the real question is why shouldn't someone learn PHP in 2020 ?
A language that's easy to make fun of but widely used is an attractive target for improvement.
As companies started adopting TypeScript/Flow into their Javascript pipeline, PHP developers realised the need for something similar in their ecosystem.
I work at Vimeo (which has a lot of business logic in PHP) and I took it upon myself to write a static analysis tool (which you can play with at https://psalm.dev). Other similar static analysis tools were developed at other places that use PHP, and together they have helped make modern-day PHP development a little more orderly.
[1]: https://symfony.com/blog/symfony-was-the-backend-framework-w...
It also seems to have declining interest after peaking in 2017[2].
EDIT: I was looking at the wrong repository, so my comment about Laravel's popularity is wrong.
1. https://github.com/laravel/laravel/graphs/contributors
2. https://trends.google.com/trends/explore?date=today%205-y&ge...
I have seen no PHP renaissance anywhere (real life, Hacker News, reddit, or anywhere else), but I also checked TIOBE[1]. PHP's popularity peaked in 2006, when it was 500% as popular as it is now.
Some highlights are union types, a JIT compiler, named arguments, annotations, and match expressions.
The approach to named arguments is interesting. It's nice that you don't have to change the signature of existing functions, but the downside seems to be that you can't enforce the usage of named arguments on callers, as in other languages like Ruby and Python where keyword arguments need to be declared as such.
function foo(string $a, string $b, ?string $c = null, ?string $d = null)
{ /* … */ }
foo(
b: 'value b',
a: 'value a',
d: 'value d',
);In Python you don't need to explicitly declare keyword arguments either (though it is possible). This is perfectly valid and working:
def foo(a: str, b: int, c: bool=None, d: float=None):
pass
foo(b=5, a='something', d=3.0)
# is equivalent to
foo('something', 5, None, 3.0)I can't help but feel that PHPs popularity is mostly tied to Wordpress, and to a lesser extend Laravel (with Symfony coming in behind that).
Not really sure the rest of the ecosystem even matters, outside those core pieces. I'd love to see it fix alot of landstanding issues, and I love that the language has moved forward. I've worked with it professionally over the last few years in various places, and I don't particularly dislike so called "modern" PHP, but its only really good at very specified problem domains (mostly, you have a website, need to display said website. I always had scaling problems for anything other than using it in the context of a template language or very straightfoward database access. Real time APIs? nope. Just couldn't get it done, too much memory pressure)
I was under the impression that PHP's stateless nature, with a whole new instance of everything coming into being for each request, somewhat sidesteps the capacity for problematic memory leaks that could otherwise exist for processes that remain alive between requests.
A couple issues here.
1. Even if the PHP process exits after each request, memory leaks during the request are still an issue. If I'm looping through 1,000 elements of an array and leaking memory each time, I could end up with a peak memory usage of 100MB when 1MB would've sufficed. That forces me to scale vertically when I might not otherwise need to.
2. Most mature applications have worker processes that may be longer-lived than serving an HTTP request. If PHP leaks memory, it's less suited to those tasks. Maybe you write those in Go instead, but then you have to ask yourself why you didn't just write the whole application in Go.
*not to take sole credit. I created RPC framework and initial API, and oversaw a small team of very talented engineers who added a significant chunk of the functionality powering Grooveshark over the years
I usually have to resort to queues, which just adds complexity where I typically don't want it.
Exhibit A of your parent's point.
The new PHP7/8 is certainly exciting, is it too late?