35 points · by schlonger0009 · 2y ago · 71 comments
I watched it myself and learned a thing or two despite also working with PHP professionally for years.
Highly recommend to also stop after each video and try to implement a quick example of what it is teaching.
- Depends on stage of study - Depends on type of concept - Depends on how the student learns the most effectively.
There's only one way I think your statement is true, and that's if you add "solely".
I just can't get behind the complexity of build steps and compiling, all just to get a website online. It's crazy. The simplicity that PowerShell (and PHP) bring to this process can't be overlooked... so I like to beat on this drum whenever I get the chance.
Choose the tool that is right for the job, and PHP can be that tool in a surprising number of cases.
I really loved PHP, but now with go+templ (https://templ.guide) I personally don't have a use-case for PHP anymore, but that doesn't mean it's irrelevant for the world.
This is the first time I've heard of Templ. It looks cool and it was really easy to set up. Apparently there are IDE extensions to enable syntax highlighting and HTML auto-completion, but is there a way to type check the templates? One of the things I love about JSX as a templating language is that errors in your markup get reported as type errors [1]. If I write `<a herf="/foo">` instead of `<a href="/foo">` and run `tsc --noEmit --watch`, TypeScript will complain until I fix the issue. You can even extend the types to support your own HTML custom elements. JSX is a first class citizen in TS (and by extension any editor or IDE with support for TS).
[1] https://github.com/DefinitelyTyped/DefinitelyTyped/blob/mast...
1. Essentially an HTML document is a valid PHP program. This is an excellent starting point for beginners;
2. PHP has a stateless API that means there's basically zero start up cost, unlike, say, loading libraries like you do in Java or even Python;
3. There's no threading within the context of a request. This is what you want 99.99% of the time. Hack extended this with cooperative async/await;
4. Because of (3) everything you allocate/use within a request context just gets thrown away. There's no persistent state (eg like Java's servlet model). Again, this is almost ideal;
5. Because of all the above, PHP hosting is incredibly cheap and accessible.
The two things I'd probably add to PHP come from Hack: a modern type system with nullable support and the collections (vec, map, set).
Regarding embedded into HTML PHP code - it's a easy for beginners but in a large application it leads to hard to maintain mix of app logic and presentation - AFAIK this feature is rarely used outside toy project for many years.
[1] https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/ (very old and some issues may be were addressed but it's hard to fix all of this without creating an incompatible language)
I've always felt that PHP could greatly benefit from a Kotlin-esque interop language with a more modern syntax and QoL upgrades, but I'm not sure if the juice is really worth the squeeze.
Edit: Jesu X. Chris, I didn’t mean to start a language war. Learn PHP if you want, I won’t stop you lol
Would I use PHP to make games? No! I wouldn’t use JS or Python for that either.
I try to use the best language for the job without letting any cargo cult biases get in the way.
Front end stuff? JS!
Backend stuff? PHP!
AI stuff? Python!
Games and microcontrollers? C/C++!
1. You will still need to learn JS, and now it may even be embedded in PHP depending on the type of app you are working with!
2. It still has horrible conventions, arrays being sorted maps has to be one of the worst design decisions, IMO its worse than having null and undefined as types. Mutlibyte strings are still an afterthought in the core of PHP. Inconsistent function naming. It's new typing system is plain worse than TS in every way. Async programming is still terrible. Needle Haystack swapparoos throughout the language.
3. It was built for the web as it stood 20 years ago, HTML embedded in code, single server sessions, cgi servers, and minimal latency server to server communication. It cannot feel more out of place today.
I will give it: Laravel is a robust framework that helps hide some of this, but its hard to hide most of it.
2. I much prefer using PHP arrays than JS arrays. All the other stuff you mentioned have never been a issue for me in the past 10 years. I don’t care about types (I don’t even remember when I had a real type bug).
3. The modern web is an over engineered mess, all the modern js frameworks have made the user experience objectively worse. Oh wow your shitty website that has some text and a few pictures is taking 900mbs of ram and 70% of my cpu? Wow very modern! What progress we have made!
Yes, you will. But to me this is an irrelevance: JS has IMO very little business near the back end. I have absolutely no patience for the JS-everywhere thing.
(It is never necessary to directly embed JS in PHP; there are always choices. Sure, you might sometimes need to briefly template your JS, but that's true of all web environments; it's fundamental to the problem)
> 2. It still has horrible conventions
It does. But for example JavaScript is still riddled with bad conventions. Look at the mess that inconsistent array/object duality, inconsistent property enumeration, has wrought across the language for a whole generation of programmers
> 3. It was built for the web as it stood 20 years ago, HTML embedded in code, single server sessions, cgi servers, and minimal latency server to server communication.
So was JavaScript.
Laravel is, I think, the most sensibly-designed web framework that has ever existed. Every single other framework I have used has disappeared too far into the developers' own biases towards tier after tier of NIH decisions. Laravel doesn't have pretensions.
(I used to love Ruby on Rails but even I remember when the people who were the talk of the developer world with their brand new easy to use developer framework did not know that GETs should be idempotent)
I'm curious, why is that so bad? It tends to be a useful property of PHP arrays.
Also for webdevelopment, I/O is often the bottleneck. This code creates an array with 1 million items, each being 'a' and then loops over each value, changing them to 'b':
$array = array_fill(0, 1000000, 'a');
foreach ($array as $key => $value) {
$array[$key] = 'b';
}
It executes in 2ms on my machine.How often do you need to create and change each element of a million item array? A roundtrip TCP/IP call to PostgreSQL is bound to be slower than that for most web servers.
How?
So even if you leak horribly, thanks to Apache/Nginx/Caddy/whatever only launching your script and then your script stops running, it basically doesn't affect you at all.
Granted, this is more like a bandage, but it works out great for beginners who just want to create their own personal dynamic homepages, something PHP does great :)
Compared to Python or JS where the standard practice is creating a server that runs constantly, and if you leak memory somewhere, your application eventually crashes as you run out of memory.
I'd rather get paid $1,000 to build something that takes < 1 day and $50-150/month to maintain something on a $20 VPS using a tried and true Web technology with tons of developer support and a stable ecosystem.
I can start a new Laravel project and with a starter kit have 50% of the site done. Auth's already done out of the box. The ecosystem is amazing. The tooling is amazing. WordPress is amazing and its ability to extend itself and build almost anything you want is amazing.
I'm moving on to the next client while someone is crying about WordPress' arcane database structure or code and they're still sitting at a text editor with some Haskell code.
All I have to do is worry about my project, not create OCD for 2 weeks on the best way to set something up out of 10 different ways.
I'm not worrying about which flavor of JavaScript framework is in popularity this week - I'm not worrying about how to deploy my Python app and setting up Kubernetes. I'm not worried about compiling my Elixir project to WASM and deploying to Fly.io to support my 1 visitor a month.
Lot of those around[0].
[0] https://w3techs.com/technologies/history_overview/programmin...
Lot of that going around; especially in venues like this, which has a lot of "Ooh! Shiny!" going on. I tend to be a bit more conservative than many; but not to any kind of extreme degree. I like new stuff, but I also like shipping, which doesn't come from the bleeding edge.
Personally, I use PHP on my backend work, mostly because it's a known quantity, and is an industrial-strength, massively-supported system, that is not going anywhere but up.
And I don't feel like learning a whole new language and API, just for some relatively minor-scale server work (I spend most of my time, writing native Swift frontends).
If it's good enough for PornHub, it's good enough for me.
That said, if PHP were, as is often falsely claimed, going away, I'd probably learn something new. I doubt it would be the tip of The Shiny Spear, but it would be a more modern system; maybe Python. I've never actually liked working with PHP, but the same could be said for most languages I've used. I like Swift.
As it is, I would still want to learn Laravel, before moving away from PHP. From what I understand, it's a fantastic framework, that makes PHP a much more effective server system.
I'd take Laravel with Livewire (and some Alpine.js) over Django any-day. Plus my gut feeling says, that React would be as pleasant as Laravel and co.
Snobbery is like saying you're intellectually superior to using a specific screwdriver or kitchen knife.