Live data from Hacker News

Learn PHP the Right Way

github.com

31–40 of 73 posts

Re: Learn PHP the Right Way

#31
post #20

Passively watching YouTube is probably not the right way to learn any progamming language.

Anecdotal at best, but that is essentially the way I learned English, and definitely the reason I think I don't have a distracting accent when talking in English.

Re: Learn PHP the Right Way

#32

Earlier quoted context omitted.

An article is not obsolete just because it's 12 years old. Honestly, in PHP's case, I don't think there's much you can say about it 12 years ago that isn't still true.

12 years ago (2012), the latest PHP version was 5.4. The current version is 8.4. The language has made major changes to both syntax and functionality.

Eh. On its own that means nothing, the other commenters make better points.

Re: Learn PHP the Right Way

#33
This playlist is a great overview.

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.

Re: Learn PHP the Right Way

#34
post #25

Earlier quoted context omitted.

An article is not obsolete just because it's 12 years old. Honestly, in PHP's case, I don't think there's much you can say about it 12 years ago that isn't still true.

It's obsolete because most of it is no longer correct. I'm not going to bother rebuting all of it, those who really want to educate themselves can use Algolia search for the link and find great comments. But from a quick glance of the start, the article cites "mysql_real_escape_string()". That function has been deprecated 11 years ago. And removed 8 years ago. https://www.php.net/manual/en/function.mysql-real-escape-…

I've searched Algolia; the comments in the original 2012 thread are mostly "yeah, it's roughly accurate and PHP sucks", the ones from 2014 and onwards are mostly "it's all lies, PHP has come long way and fixed lots of things" but with no specific examples except for that "mysql_real_escape_string()". Surely there were other improvements that could merit a mention?

Re: Learn PHP the Right Way

#35
post #9

Earlier quoted context omitted.

PHP is so much nicer to use on a webserver vs Python or JS. It’s almost like PHP was built for the web and fits it like a tailored suit! 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++!

Is it really that good for backend? 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. I…

1. I am already very good with JavaScript, I like having the language separation between frontend and backend.

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!

Re: Learn PHP the Right Way

#36
post #3

The only reason to learn PHP in 2024 is if you are specifically targeting PHP jobs. Learning PHP is like learning Perl: suboptimal. Edit: Jesu X. Chris, I didn’t mean to start a language war. Learn PHP if you want, I won’t stop you lol

I think for probably more than half of all websites out there, something like LAMP is either the optimal, or very close to the optimal solution. It's absolutely bonkers to me what kinds of tech stacks people use to render what essentially amounts to a bunch of forms.

At least half of all websites would probably be better of if their creators realised they needed something closer to a 'blog' than a 'web app'. It's especially true when it comes to the media industry, who seem to love creating the most over engineered SPAs possible for functionality that's barely changed since the 90s.

Re: Learn PHP the Right Way

#37
It's disappointing that PHP still gets hate in 2024. PHP of 2024 isn't the PHP of 2004. As someone with a bunch of experience in Java, C, C++, Python, PHP, Hack, Javascript and a handful of others, PHP is (IMHO) almost a perfect language for serving HTTP requests because of these characteristics:

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

Re: Learn PHP the Right Way

#38
post #3

The only reason to learn PHP in 2024 is if you are specifically targeting PHP jobs. Learning PHP is like learning Perl: suboptimal. Edit: Jesu X. Chris, I didn’t mean to start a language war. Learn PHP if you want, I won’t stop you lol

There's certainly a ton of use cases where php is a few minute job and anything else is 10x more or even longer just like is true with shell scripts and perl Snobbery is like saying you're intellectually superior to using a specific screwdriver or kitchen knife.

Or they're simply committed to using the wrong tools for the job out of some misguided ideology someone else handed them when they were too new to know better.

Re: Learn PHP the Right Way

#39
post #3

The only reason to learn PHP in 2024 is if you are specifically targeting PHP jobs. Learning PHP is like learning Perl: suboptimal. Edit: Jesu X. Chris, I didn’t mean to start a language war. Learn PHP if you want, I won’t stop you lol

Not if you're trying to make money and learn Web development. PHP is king.

I'd rather get paid $1,000 to build something that takes 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.

Re: Learn PHP the Right Way

#40
post #9

Earlier quoted context omitted.

PHP is so much nicer to use on a webserver vs Python or JS. It’s almost like PHP was built for the web and fits it like a tailored suit! 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++!

Is it really that good for backend? 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. I…

> arrays being sorted maps has to be one of the worst design decisions.

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.

Post reply on HN