Live data from Hacker News

Modern PHP Cheat Sheet

front-line-php.com

41–50 of 127 posts

Re: Modern PHP Cheat Sheet

#41
As a JS dev it’s nice to see php imitate some newer js syntax like nullish coalescing, arrow function, … helps me to switch between the languages.

It really needs a way to declare type of small data structures though, in a very concise way (no class boilerplate, for performance eg. going through 10000’s of entities).

PS : on the other hand I’m starting to dislike how languages become "designed by committee", and lose the purity of the original design.( thinking of JS mostly here with its gazillion rfcs)

Re: Modern PHP Cheat Sheet

#42
post #14

I'm not convinced by Enums having methods. For those of you using other languages that support this, do you find them useful?

Enums with methods are essentially a compiler supported way of having several static readonly instances on a class with a private constructor. It’s not always useful, but it can be nice, sometimes. I’ve had a few times working with C# where I’d have liked those.

Re: Modern PHP Cheat Sheet

#43
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…

JIT compilation certainly isn't fluff or bloat.

Re: Modern PHP Cheat Sheet

#44
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...

Not only shipping things faster but testing faster, scaffolding faster, debugging faster ... the tooling for PHP is much more mature than it was 6-years ago and there are so many GOOD packages out there that haven't been forked and copied 20x over.

Really happy to be working with it again, even if on the side for now.

Re: Modern PHP Cheat Sheet

#45
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…

JIT compilation certainly isn't fluff or bloat.

FFI too

Re: Modern PHP Cheat Sheet

#46
post #41

As a JS dev it’s nice to see php imitate some newer js syntax like nullish coalescing, arrow function, … helps me to switch between the languages. It really needs a way to declare type of small data structures though, in a very concise way (no class boilerplate, for performance eg. going through 10000’s of entities). PS : on the other hand I’m starting to dislike how languages become "designed by committee", and lose…

As a very long time PHP developer I say this with love, because for PHP it's actually a blessing to be moving away from the "purity" of the original "design".

Re: Modern PHP Cheat Sheet

#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?

Re: Modern PHP Cheat Sheet

#48
post #23

The comment on Numeric values is misleading: > Use the _ operator to format numeric values: > $price = 100_10; > // $100 and 10 cents Makes it sound like the underscore replaces the decimal, which it doesn't. The underscores are simply ignored by the PHP parser, so that 10_0.1 === 1_00.1. You could afterwards use PHP to replace the `_` with a comma for display purposes, and I assume that is what they are trying to sa…

Yeah, that's a terrible example since some places do use comma as a dollars/cents separator, and others don't. And some people use floats for currency (with the obvious caveats), and might read this as "_ is the same as a decimal point" . They really should just use a simpler example, like 10_000_000 being easier to read as "10 million" than 10000000.

  > They really should just use a simpler example, like 10_000_000 being easier to read as "10 million" than 10000000.
Declarations such as `$million = 1000 * 1000;` or `$seconds_in_day = 24 * 3600;` are very common, and in my opinion more readable than the ignored-underscore syntax.

Re: Modern PHP Cheat Sheet

#49
post #32

Earlier quoted context omitted.

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...

Not only shipping things faster but testing faster, scaffolding faster, debugging faster ... the tooling for PHP is much more mature than it was 6-years ago and there are so many GOOD packages out there that haven't been forked and copied 20x over. Really happy to be working with it again, even if on the side for now.

I agree.

Developer speed does not get enough coverage when comparing languages.

When I work with a Node project it's such a slow dragging build process.

Using PHP is like a fun superpower that lets me turn out things on timescales that are borderline miraculous to clients and management.

Re: Modern PHP Cheat Sheet

#50
post #15

Earlier quoted context omitted.

I really want to use PHP for one-off CGI scripts, (rsync files and done, deployed), but I really wish it had methods on primitive types. It hinders discoverability. It's annoying having to look up which function I need to use, and to find that there are many alternatives, most of which are deprecated. PHP stdlib needs an overhaul, IMO.

Wouldn't that be pretty bad for backwards compatibility?

You can always keep the old.

However I don't think it is something that will ever be done, designing a good standard library is quite difficult, especially by email and rfc.

I think it is better if the community designs one that gets a lot of traction to become de facto standard. All the large frameworks already has their own standard library.

With the performance improvements to PHP over the years it is no longer a detriment to performance to write a standard library in PHP.

And if we can get the operator overloads rfc passed we can have userland scalar objects

https://wiki.php.net/rfc/user_defined_operator_overloads

Post reply on HN