Live data from Hacker News

Modern PHP Cheat Sheet

front-line-php.com

31–40 of 127 posts

Re: Modern PHP Cheat Sheet

#31

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…

Not my cup of tea, but if you really want PHP-like with JS, EJS looks really close to "I wish server-side javascript worked like PHP":

https://ejs.co/

Just needs a FastCGI wrapper.

Another "Node, but PHP like" project that compares itself to EJS and other similar things: https://github.com/Yahweasel/nodejs-server-pages#why-nodejs-...

Re: Modern PHP Cheat Sheet

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

Re: Modern PHP Cheat Sheet

#33

The evolution of PHP has shown the difference that having engaged stewards of the language can make. Saw a list of quotes[1] from Rasmus Ledorf which I think explains it's stagnation. As someone who used to sneer at the language, modern PHP doesn't look out of place among Ruby, Python, etc. https://mobile.twitter.com/woketopus/status/1447150924846313...

I don't know how this really played out internally, but from the outside it feels like Hack/HHVM kicked the PHP core team in the gut and inspired them to improve things.

Re: Modern PHP Cheat Sheet

#34
Genuine question from a php hobbyist : what is the equivalent of Typescript’s ability to declare an object’s structure?

It’s really weird to me, I mean don’t we do this all the time? Work with eg. an $options array/obj passedto a constructor, or say, a message decoded from JSON…

I could write $name = $message[‘username’] … and there is no checks in ide or runtime, while the phpdoc will just document $message to be an object or array… what am I missing?

It looks like php devs create full blown classes to represent just about every data strcuture, but what if it’s just data and you don’t need any attached logic’ Isn’t there a concise way to declare a complex type?

Re: Modern PHP Cheat Sheet

#35
post #15
post #3

I like how PHP is evolving. I wouldn't say it's always a joy to use but it definitively improved a lot.

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?

Re: Modern PHP Cheat Sheet

#36
post #34

Genuine question from a php hobbyist : what is the equivalent of Typescript’s ability to declare an object’s structure? It’s really weird to me, I mean don’t we do this all the time? Work with eg. an $options array/obj passedto a constructor, or say, a message decoded from JSON… I could write $name = $message[‘username’] … and there is no checks in ide or runtime, while the phpdoc will just document $message to be an…

We do indeed create full blown classes for data objects. However, it is made easier with PHP 8.0 and 8.1 (released today).

Typed properties, constructor properties, and Read-only properties can significantly reduce the code bloat.

- https://php.watch/versions/8.0/constructor-property-promotio...

- https://php.watch/versions/8.1/readonly

Re: Modern PHP Cheat Sheet

#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 not to design a programming language.

Re: Modern PHP Cheat Sheet

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

It wasn't designed, it was evolved. The author said as much. Evolution seldom produce clean designs.

Re: Modern PHP Cheat Sheet

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

> Everything new added since 7.4 is just fluff or bloat.

The 7.4 did not finish the type system work. Docstrings were still needed for basic type hunting.

Re: Modern PHP Cheat Sheet

#40
post #36
post #34

Genuine question from a php hobbyist : what is the equivalent of Typescript’s ability to declare an object’s structure? It’s really weird to me, I mean don’t we do this all the time? Work with eg. an $options array/obj passedto a constructor, or say, a message decoded from JSON… I could write $name = $message[‘username’] … and there is no checks in ide or runtime, while the phpdoc will just document $message to be an…

We do indeed create full blown classes for data objects. However, it is made easier with PHP 8.0 and 8.1 (released today). Typed properties, constructor properties, and Read-only properties can significantly reduce the code bloat. - https://php.watch/versions/8.0/constructor-property-promotio... - https://php.watch/versions/8.1/readonly

Can you directly cast an object / assoc array to an instance of such a class?

If I have a function that receives eg a Message, it means an instance of the class right? So somehow my assoc.array/object still needs to be instanced, and if I do just $message = new Message($theData) … it doesn’t auto assign properties right? That would be handy though still very much boilerplate.

I guessthe language is just designed for how it’s been used so far, may e it will change if JIT makes php more open ended in its uses.

Post reply on HN