I helped on the HyperPHP documentation team and debugged a bunch as I wrote some machine learning stuff in PHP as an exercise in developing it with the HyperPHP translator.
I enjoy writing it. I find myself using Python more and more simply because it's easier to find better outsourcers with academic projects in their background (a niche I'm in and something that Python was literally built to service), but PHP 7+ has been great. I don't particularly care for the unbridled hate that comes with PHP historically being "bad" and also extremely popular.
Further, avoid == completely, pass the strict argument to functions that do comparison like in_array(). You don't want https://3v4l.org/mcpi7 to happen. You want https://3v4l.org/Yo6tI instead.
Your functions in 7.1 finally can typehint for iterable (array or Traversable object) although the array_* functions still only accept arrays. There are nice little libraries papering that over and installing libraries is easier thanks to composer.
PhpStorm gives you a fantastic IDE. The language is still ridiculously easy to deploy thanks to a zero share model.
Basically: most of the landmines can be cordoned off with putting declare(strict_types=1) on top of your files or bridged over by libraries like nikic/iter. A few are left but they are easy to avoid.
Admittedly, even on a good host it won't scale as ridiculously well as a lambda function does, but I'd wager scling from 1 to 1 million req/s in an hour and then back again is a pretty marginal use of Lambda. All the other advantages boil down to not having to manage your own server. Just deploy the code, and that's it.
Well, PHP has had this for decades. And I believe that people should really consider this when choosing a language. I don't know of any other language that you can code a backend in without thinking about servers and daemons and keeping nginx up to date, without getting vendor locked-in to something like Lambda or Heroku.
This is also why I don't really see the point of Hack/HHVM for any new product: If you're going to install some random runtime on some server as well, there's probably more ergonomic languages you can choose.
In fact, it's baffling that other popular languages for web development - such as Python and Ruby - have failed to address this issue of easy server installation. Developers underestimate how important this is.
If you want to sell a self-hosted solution to your customers, especially if they are small or medium-size businesses, it's impossible to offer an easy self-install solution using other languages (i.e. easy enough for non-technical users to follow instructions for install success).
Having a ridiculously easy web app installation process for servers would unlock countless opportunities for developers to reach more users or customers.
Programmer Jeff Attwood wrote about this in a critical post about PHP:
"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."
Attwood goes on to say we should:
"build compelling alternatives and make sure these alternatives are equally pervasive, as easy to set up and use as possible." [1]
That was written in 2012. And yet here we are in 2017 and there is still no other language that matches PHP for ease of server install, or for choice of hosting providers. I repeat: developers underestimate how important this is.
I've wondered for years where else this aspect of PHP might be appreciated and show up in another ecosystem. In retrospect it almost seems obvious that it'd more likely appear in the form of convergent evolution combining another benefit that's higher status in the industry if less frequently needed.
Because if so, there's quite a few drawbacks. You're generally not in any sort of scalable setup, no high availability, you're on a shared box with other customers, you are susceptible to IO constraints on the shared disks, etc. You're still going to need a database of some sort for most applications....
As you describe acceptable use-case for 99% of all projects.
PHP - at least if you're working on a modern 7.1 code base - isn't perfect, but it holds it's own. You do need at least one experienced person to stop you making serious mistakes (and with PHP, there are a lot of mistakes to make!), but in my experience that's true of every language.
Syntax is still a bit janky, the standard library has function names and parameter orders that seem to have been created by feeding the source code through a blender, and nested ternaries are a trap for the unwary due to their completely broken associativity rules.
On the other hand, the syntax isn't that bad, the gradual typing story is starting to get pretty solid, composer is really nice, IDE support is great, and the ecosystem is stable, mature, and deep. (And you shouldn't be using nested ternaries anyhow, come on, this isn't a code golf competition.)
As a general rule, I find the project I'm working on now to be slightly more pleasant to work on than the Python/Django app I worked on before, and significantly more pleasant than any node app I've worked on.
Five years ago, if you told me you were starting a new serious project using PHP for the server side I'd have thought you were probably making a mistake. Today, I wouldn't blink, again, not because it's perfect or the best, but because it's solid and mature and good enough.
also, they've refused to implement native multi-part formdata parsing in anything other than POST requests and dont expose a good/safe way to get this done either, leaving PUT/PATCH request parsing up to the users, which is shitty and has been asked for a long time ago [4]. this means you can't rely on language-level support for basic REST, leaving it up to frameworks/routers.
it's crap like this that moved me on to other languages. PHP7 is fast though, and gets shit done. i'll give it that. i don't see any reason to start a new project with it when you can have node/js/vscode (or better).
[1] http://phpsadness.com/sad/30
[2] http://grokbase.com/t/php/php-internals/14cdp789nk/fix-incor...
[3] http://php.net/manual/en/language.operators.comparison.php#l...
Oh man. Remember that drama in the internals when trying to remove T_PAAMAYIM_NEKUDOTAYIM ?
Symfony and Zend have a large library with various functionality and you can pick and choose what you like. The php Composer lets you control dependencies easily.
The main problem is that there are almost too many frameworks and the language has a bad reputation (legacy warts from old generations). I maintain java and perl websites too, and find the php ones easier to maintain.
[Edit: read what Slack devs wrote about PHP, their server side is written in PHP https://slack.engineering/taking-php-seriously-cf7a60065329 and beside that Facebook uses PHP/Hack and MySQL as core tech)
The syntax is inspired by Perl and C family (C/C++ and Java) and many functions one knows from C family are inbuilt. The advantage, it's friction free, hassles about memory management, dynamic typing allows rapid development, experience, etc.
The focus of PHP is all around the web, it was the first successful language designed for the web. All inbuilt functionality has been carefully selected, everything is built in and can be used from the start. You only need to copy the files via (S)FTP or SCP to the shared hosting server (nowadays it would probably be called "server less", e.g. Amazon Lambda) and press F5 to reload the page. It's basically the easiest environment to start, and can be Sean as the successor of Visual Basic 6 as the entrance for many younger devs after 1999 in the programming world. And the good thing almost all the negative cruft of the earlier era got removed with PHP5 and PHP7 (and the compatibility is still there, old PHP4 code still runs (or with minor changes)).
Today most languages like Python, Ruby, Perl, Java, etc also offer asynchronous frameworks to let them scale a lot better - compared to them, you don't have to change your code with PHP, it was always shared nothing and is fast by default - according to benchmarks often faster than Python, Ruby, etc.
Nodejs, Go and Java offer nowadays very comparable performance (with Java and Go being slightly faster) in common benchmarks and real world. Nodejs with (vanilla) JavaScript and PHP allow for faster development - no static typing, no compiling step.
Erlang/Elixir is the latest hype. Beside some different terminology and focus around functional language parts, actors model, the inner working of ErlangVM and e.g. HHVM are not so different. The shared nothing, one thread per execution model offers similar results. ejabberd XMPP server software written in Erlang and used at WhatsApp (now part of FB) revived the interest of Ericson Erlang eco system. PHP can handle such chat services as well, see Slack. https://slack.engineering/taking-php-seriously-cf7a60065329
And Elrang processes are not OS processes, though I get your main point.
I been porting over a game from node/express to phpsocket.io. I'm finding the async server more stable.
A few examples:
Forge and Envoyer: setup and manage your VPS in a breeze and deploy your code with zero downtime.
Spark: create a SaaS product in literally a matter of minutes without having to care about all the boilerplates
Echo: real time notification across multiple channels (mail, Pusher, Slack, etc.)
Passport: OAuth2 API server as easy as it can be
Scout: Redis/Algolia search with just a couple of lines of code
Dusk: test your app easily both for unit and browser testing
Cashier: payments with Stripe and Braintree in a breeze (both for one time payment and recurring ones)
Socialite: OAuth for all kind of services (Facebook, Twitter, Google, ...)
And beside all this, there is the excellent Laracasts by Jeffrey Way that made me learn not just Laravel but PHP and JS in general in a really great way.
And I could go on talking with the great and simple queueing system, the perfect integration with VueJS that I love as well, ...
As you can see I'm a big big fan of Laravel in general and I hope that it will become popular in HN especially over time.
Still, most of the uglies of the languages can be learned and then circumvented in action or by using proper tooling.
PHP 7 followed the general trend of bringing stronger types into dynamic languages. You can now annotate function arguments with types. I believe that makes it possible to write a static type checker, but I haven't seen one yet.
Why people hate it? I cannot speak for the whole public, but I dislike the language because it let me down. My first experience with PHP is from 1998ish, when I saw it as a way superior option to Perl, and ported a web application to PHP.
After that, I learned about programming. I didn't touch PHP again until 2013, when I got a job in a PHP shop. I went there with an open mind, thinking that the programming language is one of the least important things when building products. But every step of the way, PHP somehow got in my way. It hadn't gotten better in ways I would've liked. It let me down.
Now, of course, I don't work there anymore, so the amount of fucks I give at the language is slowly declining. Soon, I'll be able to not care at all.
1. PHP is very welcoming to beginners. That's of course a good thing, but the downside is that it's actually quite difficult to get quality answers on StackOverflow, which is rife with clueless trial-and-error answers and "Just use <completely unrelated heavy framework>, dude" kind of responses
2. PHP started out as a simplistic server-side templating/expression language; which is fine by itself, but without any kind of injection prevention is incredibly naive, and the reason for so many DDOS botnets. Of course, using embedded PHP (eg. in a processing instruction in your otherwise static HTML) hasn't been considered best practice for years. But then why use PHP at all, when this distinguished feature isn't usable, and neither is PHP a standardized language, nor is its stdlib any good. In fact, this retargetting of PHP with little or no architectural oversight (from an expression language into a full-blown app language with OOP and whatnot) seems endemic in the PHP world, and is also the case with eg. WordPress.
That said, I quite like the PHP community for their practical-mindedness and their get-stuff-done mentality.
https://github.com/FriendsOfSymfony/FOSRestBundle/issues/980
I left the PHP world a few years ago, but I still have to go back occasionally to manage a few old projects. I recently upgraded one to PHP 7.*. It's soooooo much faster than older versions I consider it a must have for anyone working on PHP.
That said one thing I don't regret is not having to deal with composer again. It's basically a shittier version of npm, with a fraction of the speed and a fraction of the logic built in. I have projects that have installs that aren't idempotent due to weird composer caching issues. Composer is a good thing but I can't help but wonder if PHP simply isn't fast enough of a language to build a package manager in.
Composer is so much faster than npm in my experience but haven't moved to yarn so I might be missing some speed.
Custom PHP framework we built took into account the way PHP is executed: you are stateless and need to setup everything on every request (runtime is fast to start with FPM and opcode cache). Namespaces based cheap autoloader worked great. No composer. We used singletons for getting the configuration and connections to DBs. There was almost no setup code that needed to be run every time other than loading .ini based configuration and connecting to the DB. Our webapp responded under 20ms (DB and Sphinx included), and I could get it to respond in 1 ms for things where we needed to be quick and didn't have to output HTML with Forms. I was really small and you could read the whole framework code in 1-2 hours. It worked with SQL in a reasonable way. You didn't have to write your SQL for simple CRUD, but for larger things involving joining multiple tables and more complex expressions we wrote native SQL.
I switched jobs, and started with Symfony 3. The thing felt like some Java framework, but poorly documented and harder to use than it should be. It had lots and lots of setup code done before handling every request. There's a whole DI framework with it's own tons of setup code for every component. And you have to do setup even though you don't use the component in that particular request. There's ways of doing lazy setup, but you still waste time to wire that up. Framework overhead can be 30-100ms. Other modern PHP frameworks have similar overhead. I know that there's PHP-PM, to save some of that work that isn't really $_REQUEST specific.
Everybody is using type hints wherever they can, and it feels as verbose as Java, but without compile time type safety, and you can't really put type information everywhere (class members for example). Even though PHP runtime has made great progress (it's probably the fastest interpreted language, and it's great it has reference counted garbage collection), it feels like language is struggling to find it's identity, with it taking a lot from Java and still coping with ugly legacy ($, having to use $this inside a class function, php.ini, features for supporting templating even though it's rarely used as a templating lang in modern frameworks).
Doctrine and it's verbosity feels very ugly to me.
Learning Python and Flask (as an example) was much more enjoyable than switching from a nimble custom PHP framework to Symfony.
I'd argue you can write fast, simple and maintainable PHP, using state PHP runtime has setup for you ($_POST, $_GET, $_SERVER etc), namespaces and a namespace based autoloader, trying to use pure functions when you can (using static classes shouldn't be a sin - just to split your code in sensible parts), and using general good practices for writing readable and maintainable code (avoid long functions, huge classes, too much block nesting, decoupling, naming things in a good way). With some conventions you can write a decent and productive framework quickly, but you could do that with a nicer language too, so what's the point?
This is also the overarching feeling I get from the big PHP frameworks: Java envy. They picked an architecture which is perfectly sensible in Java, but slow by design in PHP. You also notice this in the language features being added, where gradually PHP is turning into Java. On the Java side instead there is Scala envy, with Java slowly turning into Scala.
I don't mind PHP taking good ideas from Java though, PHP 7.x is much improved and the community overall seems to be moving in the right direction: take the good ideas from Java, without taking on the worst excesses.
Except for the time when you are 10 times more proficient in PHP but none of those languages. Then no, none of those languages are better for the job.
Some times a different language can so utterly change/simplify your approach to a problem it's 100% worth it.
Visual Basic is still a language that many people know better than other languages, but I'd not advise those people to stay on VB just because they know VB. And PHP is getting a fresh coat of paint but that doesn't mean it isn't antiquated - what other web based programming environments provide a CGI model where scripts are in the public directory? How many of them are HTML with directions for the actual programming language?
If PHP is intended to stand on its own as a web development language, they've missed a few bits of low hanging fruit already. Like, take HTML out of the language. Package PHP with Composer. Allow for a new app base model where apps have their own FCGI servers and routing is done in PHP. I mean why not? These are things that modern users of PHP already try to accomplish, sometimes with [ugly hacks that are prone to security issues](https://www.acunetix.com/vulnerabilities/web/nginx-php-code-...).
I don't care if people think I'm just being a hater for the sake of it. I really think PHP is a dead end, and I think that because it seems the focus for PHP development has been toward making older software like MediaWiki run better rather than make PHP a better platform overall. As far as scripting languages go, it has a history of confusing, non orthogonal behaviors, legacy cruft, bad documentation, and designs that promote or directly cause security problems. And it has such a problem with memory management that the gold standard is to simply kill the PHP instance every N requests.
Work with off-the-shelf managed hosting.
Go build your client's new website in go, and then spend 80 hours trying to make it work with their $5/month hosting
Let's say my friend runs a store. He needs a website. I can:
1. Find a $5 a month shared hiding plan. As it's Shared, they don't let you start servers, so go (as well as python) is out of the picture (unless you run it as a CGI - yuck). You develops the site, sell it to him, and fix on contract. You never have to do another thing for him.
2. Get a $5 a month VPS, spend another $1 a month (or more) on an S3 backup. Ensure said backup works (try it out once in a while). Keep OS up to date.
Which is easier? Which is more maintainable?
Does anyone think that if WordPress was written in Python it would get nearly as much traction?
That's why PHP won the internet (and that VPSs were extremely expensive until a about a decade ago) - servlets where around for a long time but you couldn't run it on a shared server - made it dead on arrival.
Ok, I can dig it.
Instead of wearing sneakers you should wear cloggs or flip flops.
Well, actually I came to dislike static typing so much that's a big point against languages IMHO. I concede that it would have saved me time with data occasionally going to the wrong argument/method/function but every time I understand that I'll have to type almost useless stuff like Map(<String>,<String>) I hit back and return to HN home page. Moving to dynamic typing was as liberating as moving away from malloc/free to garbage collection.
I think I could stand languages with implicit typing. All I want is not to have to annotate my code. I'm happily paying some time and tests for that.
Btw, I don't like people downvoting to express disagreement so I'm upvoting you. My +1.
What? A whole lot of web apps these days are built in Python, Ruby, or JavaScript, none of which are statically typed languages. Do you mean a strong type system?
Though as I always say: use the right tool for the job. And for a lot of jobs dynamically typed languages and framework offer a lot to the developer.
https://stackoverflow.com/questions/2690544/what-is-the-diff...
How is programming in PHP these days? I haven't used the language since 4.x-5.2 or so. I wrote it off completely when Hack and HHVM came out due to the nuances between it and PHP proper (not to say either is bad, it was just another barrier, and set of choices I didn't care to deal with). I typically write Ruby, Elixir, and some JVM based languages these days. Any new features or language changes that make it more pleasant or any good use cases compared to my usual languages? I will add using it anywhere, while a valid use case, isn't something particularly attractive to me.
Edit: just wanted to say thanks for all the good comments posted so far!