8 ms·
Honest, sincere, question here: 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
by rubyn00bie 9y ago
Honest, sincere, question here:
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!
- smt88 9y agoIt's not a terrible experience, but it is truly baffling that anyone would start a project in it today. A good static type system is too useful and important.
- micaksica 9y ago> A good static type system is too useful and important. 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?
- rubyn00bie 9y agoI assume mean strongly typed and I can agree with them to an extent. While it does add slight overhead when writing code (not enough to matter I think) it does help eliminate a bunch of errors/edge cases you'd have to unit test for in an dynamically typed language. 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.
- deevus 9y agoThere's no concrete definition of strongly typed, either. https://stackoverflow.com/questions/2690544/what-is-the-difference-between-a-strongly-typed-language-and-a-statically-typed https://stackoverflow.com/questions/2690544/what-is-the-diff...
- deleted 9y ago[deleted]
- pmontra 9y agoThat's the last thing I look for when evaluating a new language. 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.
- noway421 9y agoThank you for the insightful comment, all of a sudden static typing increasing coding friction makes sense.
- jjeaff 9y agoI still do my saas projects all in PHP. I mean, I'm not building NASA control software it anything, but I have incurred very few problems due to dynamic typing. Not to mention the fact that I can hire php devs for half of what a ruby dev wants these days.
- jchw 9y agoPHP7 has improved life when dealing with legacy systems, but I think all in all you're better off not building new stuff in it. There are almost always better tools for the job than PHP, like Django, Rails, Go's net/http, etc. depending on the kind of thing you're writing.
- stephenr 9y agoSo, framework-vs-language arguments without any kind of explanation why are in huh? Ok, I can dig it. Instead of wearing sneakers you should wear cloggs or flip flops.
- deleted 9y ago[deleted]
- jchw 9y agoIf you want more detail on my position, I wrote more here: https://news.ycombinator.com/item?id=14884665 https://news.ycombinator.com/item?id=14884665
- bdcravens 9y agoI haven't built anything in it (and rarely touch PHP, aside from some Wordpress ecosystem stuff), but if I were to build a web app in PHP today, I'd build it in Laravel vis-a-vis "raw" PHP.
- icelancer 9y ago>There are almost always better tools for the job than PHP, like Django, Rails, Go's net/http, etc. depending on the kind of thing you're writing. 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.
- deckiedan 9y agoIt depends. I'm way more proficient in Python than anything else, but I'll still reach for PHP fur a single page template / dynamic report, or awk for some jobs, bash for others, Perl if there's exactly the right CPAN lib, ditto ruby or node, c for some jobs... Some times a different language can so utterly change/simplify your approach to a problem it's 100% worth it.
- leeoniya 9y agoi think PHP has the opposite problem of JavaScript - a build-in function library that's too big and very inconsistent. much of http://phpsadness.com/ http://phpsadness.com/ remains in v7+. i tried to get them to change their long-standing, self-admitted improper ternary associativity [1] or at least deprecate it in v7 but it resulted in a huge bikeshed (despite no one actually encountering code that depended on the wrong behavior which has been discouraged for many years) and died a fast death [2]. their "if it's documented [3], it ain't broken" stance is pretty toxic and they maintain BC to a fault, IMO. 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 http://phpsadness.com/sad/30 [2] http://grokbase.com/t/php/php-internals/14cdp789nk/fix-incorrect-ternary-associativity-for-7-0 http://grokbase.com/t/php/php-internals/14cdp789nk/fix-incor... [3] http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary http://php.net/manual/en/language.operators.comparison.php#l... [4] https://bugs.php.net/bug.php?id=55815 https://bugs.php.net/bug.php?id=55815
- vatotemking 9y ago> i tried to get them to change their long-standing, self-admitted improper ternary associativity [1] or at least deprecate it in v7 but it resulted in a huge bikeshed Oh man. Remember that drama in the internals when trying to remove T_PAAMAYIM_NEKUDOTAYIM ?
- detaro 9y agoFor those that (like me) hadn't heard of it: https://philsturgeon.uk/php/2013/09/09/t-paamayim-nekudotayim-v-sanity/ https://philsturgeon.uk/php/2013/09/09/t-paamayim-nekudotayi...
- icelancer 9y agoIt's fine. I still write a decent amount of PHP. I also maintain a Wordpress-backed CMS that processes payments and it works just fine to the tune of several million dollars per year, a figure that most people on HN start planning for concurrency, scaling, and doing tons of premature optimizations before hitting. 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.
- acomjean 9y agoIts good. We use silex/twig for development. Sites/ form processing is pretty straight forward and easy and I like the "microframework" idea of not being too opinionated. 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.
- skrebbel 9y agoPretty independent of recent improvements, but one thing I feel people are forgetting about PHP these days is that, when given to a good hosting provider, PHP is essentially "serverless" programming, but without the vendor lock-in stuff like AWS Lambda give you. (and without the hype) 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.
- debaserab2 9y agoPHP isn't serverless in the same way a lambda function is at all. You still need to host something that responds to HTTP requests and passes them along appropriately to PHP. Just because it has a share nothing model doesn't mean you don't need to provision servers. You still need to do 90% of the work.
- joshribakoff 9y agoI think he meant you can easily find $5 "unlimited" php web hosts. So for all intents and purposes it's serverless as in you can use it on a shared web host, where you do not have to manage the server because the hosting company does it. Not that it's literally serverless. Even lambda uses servers obviously. They just abstract it away which is what he meant. Clearly all cloud offerings are backed by servers, it's just abstracted away to varying degrees
- cutler 9y agoFor $5 a month you can get a Linode VPS with 1GM RAM. After the one-off learning curve of Docker you can image these servers and get much more for your money than what any shared hosting provider has to offer. Better still, you're not tied to PHP either.
- vrodic 9y agoIt's weird for me. I used to write both Java and PHP in the past. 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?
- deleted 9y ago[deleted]
- chx 9y agoThe biggest grievances stem from PHP wanting to please you and convert things from one type to another even when it really, really shouldn't. Adding variadics in 5.6, return and scalar types in PHP 7 tunes down this sort of crazy. Not fully, though. String comparison is still broken -- use strcmp() and be happy. Using anything else is dark and full of terrors. Well, at least it's not transitive https://3v4l.org/goSYX https://3v4l.org/goSYX Further, avoid == completely, pass the strict argument to functions that do comparison like in_array(). You don't want https://3v4l.org/mcpi7 https://3v4l.org/mcpi7 to happen. You want https://3v4l.org/Yo6tI 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.
- Vinnl 9y agoDoes PHP have linters or something that force you to use the practices you described? I find in Javascript that works pretty well to restrict the language to a sane subset.
- _cereal 9y agoYou can use phpmd: https://phpmd.org/ https://phpmd.org/ or phpcs: http://cs.sensiolabs.org/ http://cs.sensiolabs.org/
- frik 9y agoPHP has some design decisions (e.g. shared nothing architecture) that used to be laughed about - nowadays it's obviously known as a big advantage - PHP can scale linearly with no overhead. [Edit: read what Slack devs wrote about PHP, their server side is written in PHP https://slack.engineering/taking-php-seriously-cf7a60065329 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 https://slack.engineering/taking-php-seriously-cf7a60065329
- vrodic 9y agoUnless you are using ReactPHP it's not really for real time apps.
- vesak 9y agoPHP in general is easy to write. Philosophically, it's all over the map due to mostly historical reasons. People say that the current development team are making it better and I don't disagree. There's just so much you cannot do when the core is so shakingly built. 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.
- debaserab2 9y agoIt's still kickin'. 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.
- joshribakoff 9y agoMy biggest complaint is that it's associative arrays are different than objects. So serializing and unserializing json can become a nightmare. This is easily circumvented by being careful to be consistent. But big libraries like symfony will change your json around and break things. In node it's just not an issue
- wolco 9y agoWhen you decode json there is an option to set a flag that will allow you to use arrays or objects.
- joshribakoff 9y agoYes I am well aware but the rest of the community didn't get the memo https://github.com/FriendsOfSymfony/FOSRestBundle/issues/980 https://github.com/FriendsOfSymfony/FOSRestBundle/issues/980
- tannhaeuser 9y agoI can't answer your question, but I'll tell you why I didn't choose PHP many years ago for a web app: 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.
- concede_pluto 9y ago"Welcoming" is not a good thing. The worst thing you can do with a bunch of clueless people is make them prolific at writing code they don't realize is unreliable. We should be teaching the minority who have the aptitude and turning away the rest.
- Lazare 9y agoVery good, honestly. 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.
- marcusbrown 9y agoI've been using PHP for many years now and I was very close to switch to NodeJS or Go a couple years ago until I discovered Laravel. That changed my view of PHP completely and it improved my code quality and potential by a 10x factor at least. I think that what Taylor Otwell has done in the last years with Laravel and with its ecosystem has been really underestimated. Not just for Laravel that is an excellent framework in my opinion, but especially with all the other products and libraries that he built along the way. It covers all the needs I had in building my last few SaaS products and it made my life soooo much easier. 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.