Live data from Hacker News

Modern PHP Cheat Sheet

front-line-php.com

111–120 of 127 posts

Re: Modern PHP Cheat Sheet

#111
post #108

Earlier quoted context omitted.

Anecdotal - my experience is the opposite. I have two large PHP side projects currently (vanilla and Drupal) and I find working with PHP and Composer to be a much slower experience overall than my day job developing with TypeScript/Node and JavaScript/React.

I would guess that a lot of the slowness is not from PHP itself, but the way your specific projects are using it. With the vanilla PHP project, the slow down may be caused by poor design decisions from other developers. With Drupal, the code quality of the core is generally okay, however the added inertia may come from a "square peg, round hole" situation, where the CMS is being used for an obscure purpose for which…

[deleted]

Re: Modern PHP Cheat Sheet

#112

I'm using Laravel/PHP for a new project and it's been a joy . A true joy. After spending the last 6+ years writing backend services in Node, PHP feels like a breath of fresh air. No restarting the server, no compiling errors from babel/typescript wackiness, no blocking threads, server-side templates out-of-the-box, and so much more. PHP has come a really long way, I really hope to see it's resurgence some day after e…

[deleted]

Re: Modern PHP Cheat Sheet

#113

Earlier quoted context omitted.

This might be true for the web but for CLI apps etc I don't think this holds the case. It’s exactly 180 degrees for me. Node js just seems to be super fast. And with typescript its heavenly. I don't make a website and working on node js is fun. In PHP it is like doing something esoteric. Just a simple argument parsing is so hard in php compared to node js. In nodejs I use meow and even without docs, I can parse cli e…

Stuff like argument parsing is left to frameworks. Laravel’s Artisan command system has all sorts of built-in functionality for exactly that.

I don't want to install Laravel for cli apps. For that most devs use symphony

https://symfony.com/doc/current/console/input.html

Installing laravel for cli is like buying thread ripper to run minesweeper.

Re: Modern PHP Cheat Sheet

#114
post #81
post #37

Having used PHP since version 4 (20 years ago), I can say with confidence that its had its peak. Everything new added since 7.4 is just fluff or bloat. Fixing long standing bugs and performance improvements is fine, of course. But everything new they introduce adds to the pile of warts that's PHP. I highly regard those that try to improve it, but with the current direction it'll remain the colloquial example of how n…

I found that php8 has brought numerous features that will formalize things I am currently doing as hacks and workarounds. Exceptions as expressions--I can stop writing, `$x = $context['x'] ?? ThrowWrapper::missingValue('x');` Named Arguments -- I use a hacky diy `Reflection` heavy version of this for an RMI/dispatch where json key-vals mapped to function params. Static return type and union types -- I have been relyi…

Thank you. I don't need any of those, though. $immutable->getAttr() is easy to mock, easy to override, and allows for custom behavior (e.g. return clone $this->Attr).

Static return type, useful but since I use interfaces for everything it's not really needed. Union types, also not really needed because either 2 interfaces share a common ancestor or I'll have separate methods for different types. But most of the time, I encapsulate things behind interfaces that do one thing, so having different methods per type can often be avoided.

Named arguments are a pain for me since now I can't change parameter names anymore. This is particularly annoying with different coding styles in dependencies vs my own code. My code ends up not conforming to the coding standard that I've used since it was introduced (PSR-2R).

Exceptions as expressions is a nice to have, but exceptions in general are a thing to avoid doing. Not that things can't go wrong, not that chugging along in the face of errors is good, of course it's not. But if you have a lot of exceptions in your code, that's a smell of bad design. I've got 13 different exceptions used 20 times in total, over 4683 LoC on my current project. Mostly, whenever one of them is triggered, whatever I changed last was incomplete and led to an inconsistent configuration.

That said, your use case for PHP is probably very different. Especially since I don't care much at all about performance anymore. I used to, but CPUs are so much faster nowadays and PHP itself has improved.

Re: Modern PHP Cheat Sheet

#115

Earlier quoted context omitted.

> From what I have seen, older people in our trade seem to recommend against PHP due to it having a terrible relationship with consistency, functionality, performance, As an older person in the trade, I don't agree with the other older persons. Only consistency is a problem with PHP code, and that is largely NOT caused by PHP. Inconsistency is the product of developers coding without any real thought about how to abs…

I am honestly and truly trying my absolute best, but no matter how hard I try, I again and again completely fail to sufficiently and comprehensively put into meaningful words how the inconsistency of the PHP language doesn’t play a role AT ALL when building actual web applications for actual users. It just. Doesn’t. Matter. Choose Symfony or Laravel, and you are in for a wonderful development experience, from setup t…

I think you've sufficiently and comprehensively put it into meaningful words above!

The truth is, those who care to use the language properly know this already. Those who wish to dismiss it always will, and this happens to be an easy angle of attack.

Re: Modern PHP Cheat Sheet

#116

Earlier quoted context omitted.

Stuff like argument parsing is left to frameworks. Laravel’s Artisan command system has all sorts of built-in functionality for exactly that.

I don't want to install Laravel for cli apps. For that most devs use symphony https://symfony.com/doc/current/console/input.html Installing laravel for cli is like buying thread ripper to run minesweeper.

Use whatever framework you like; the point is PHP leaves it largely up to them.

Re: Modern PHP Cheat Sheet

#117
post #32

I'm using Laravel/PHP for a new project and it's been a joy . A true joy. After spending the last 6+ years writing backend services in Node, PHP feels like a breath of fresh air. No restarting the server, no compiling errors from babel/typescript wackiness, no blocking threads, server-side templates out-of-the-box, and so much more. PHP has come a really long way, I really hope to see it's resurgence some day after e…

It's so nice to see a comment giving PHP the praise it deserves. Honestly, PHP is a good, if not great, language to use for building solid web apps fast. People seem to love to hate it because it's the "cool" thing to do. Yet PHP developers continue to ship things faster, while JS devs are probably still fiddling with their Node environment setup...

Much more than most other languages, PHP is purpose-built for serving web requests.

For example, PHP could get along without async/await and promises in a lot of situations, because threading was effectively subcontracted to the underlying web-server. You could just treat, say, a curl call as blocking-- resulting in a simpler code flow-- knowing that wouldn't lock your entire web server.

Re: Modern PHP Cheat Sheet

#118
post #93
post #86

Earlier quoted context omitted.

Having been out of PHP for several years now, I assume that needs a === instead of ==? It's unfortunate that we have the need for a ===, but it's no different that JS in that regard.

The underlying issue is that while md5() thinks it is returning a hex number, if the hex number starts with 0e, php thinks it's 0^ .

[deleted]

Re: Modern PHP Cheat Sheet

#119

Earlier quoted context omitted.

Hiring developers is rarely considered as well. I can hire a top-notch PHP engineer for half of what a mid-level JS engineer would be asking. It's not that PHP engineers are less qualified than JS. I think bootcamps shifted the market for JS developers and now really good engineers cost an arm and a leg while good junior engineers start around the $100k mark. The whole JS salary market is insane and as a startup, I c…

I think it’s interesting to me, as I see these comments a lot with PHP specifically and there is at any honest pushback on this, so here’s my attempt: Just pay what good engineers should be paid. If there are PHP developers out there not getting the same salary as a their peers like this post mentions, you should leave that job for a better one. Please demand better, PHP developers, for all of our sakes. Business alw…

I agree but I'll counterpoint for just a moment. A lot of mature PHP engineers seem to be from Europe, or rather non-American. I'm often finding it's American salaries that are crazyyyy high, but factor in that health insurance isn't spectacular here it might all balance out.

I've run no numbers, I have nothing but infrences to base this on, but hiring a mature PHP engineer in Europe would 100% be cheaper in the long run than hiring a junior/mid-level JS engineer anywhere else.

Re: Modern PHP Cheat Sheet

#120
post #47

I've never understood why some programmers like to use ligatures, especially on a cheat sheet like this, which will be used primarily by people who aren't familiar with the syntax. It's not 'a' ⇒ 1, it's 'a' => 1, just write it out the correct way. Why are you trying to be fancy?

Because the characters '=>' have been used to simulate exactly the character '⇒' : to mean an arrow, not e.g. "equality then greater than".
Post reply on HN