News for hackers. Stuff that matters.
Re:25 Years of PHP by TedDoesntTalk on Wednesday June 10, 2020 @10:51AM (#23477609)
> PHP, on the other hand, is basically just worse-Java

It’s much more like C than Java. And Java was in its infancy when PHP came out so it makes sense that it’s inspired more by C than Java.

Re:25 Years of PHP by ragnese on Wednesday June 10, 2020 @10:54AM (#23477641)
Incorrect. Old PHP was more like C. If you see a modern, best practices, PHP code base today, it reads like Java 7 did in 2011.
Re:25 Years of PHP by waheoo on Wednesday June 10, 2020 @11:04AM (#23477817)
Whats old is new again.

Laravel et al read like java. Nobody wants that crap anymore. Everyones moving codebases back to more procedural styles with a good dose of functional leanings towards immutable values.

Re:25 Years of PHP by ragnese on Wednesday June 10, 2020 @11:18AM (#23478023)
Which is basically impossible to do in PHP. How do you make a deep copy of an input argument to avoid mutating it?

How do you do a map+(filter|reduce)(+array_values) on an array without looping over it THREE times?

Re:25 Years of PHP by leadingthenet on Wednesday June 10, 2020 @12:46PM (#23479182)
You’ve convinced me never to use PHP if I can help it
Re:25 Years of PHP by DCoder on Wednesday June 10, 2020 @12:38PM (#23479070)
I'd say that Symfony reads like Java, whereas Laravel reads like a weird copy of Rails.
Re:25 Years of PHP by jimmaswell on Wednesday June 10, 2020 @12:44PM (#23479158)
PHP is way less verbose. I wouldn't say it really looks like Java, maybe more like C++.
Re:25 Years of PHP by ragnese on Wednesday June 10, 2020 @12:53PM (#23479283)
Stop looking at the syntax, then. PHP semantics almost completely match Java's- single inheritance, no const, everything is a reference, effectively no top-level functions, etc.

And in what way is it actually less verbose? It's almost identical to Java...

Re:25 Years of PHP by jimmaswell on Wednesday June 10, 2020 @01:50PM (#23479964)
As in defined outside of any class, object, or interface? PHP has a million of those and people write their own that way all the time. Everything is certainly not a reference and constants exist. Are you just talking about some narrow subset of PHP used in some frameworks?
Re:25 Years of PHP by ragnese on Wednesday June 10, 2020 @01:59PM (#23480073)
I feel like your reply needs a little more context. Is the first part of responding to my claim of "effectively no top level functions"? If so, my response is that no public code seems to use them and they're much more of a pain in the butt to use because the PSR-whatever autoloader stuff only picks up classes. It's way more idiomatic to write static methods on a class- exactly like Java.

"Everything" is a reference as in "every instantiated class". Again, exactly like Java. Java has primitives. Any data type YOU write is a reference.

PHP is almost exactly Java 7, but with better null handling and way worse containers.

Re:25 Years of PHP by jimmaswell on Wednesday June 10, 2020 @02:27PM (#23480422)
No public code uses echo, strlen, function_exists, is_array, count, or intval? I find this really hard to believe.
Re:25 Years of PHP by ragnese on Wednesday June 10, 2020 @02:48PM (#23480640)
I'm trying to give you the benefit of the doubt here, but I'm really suspecting that I'm just falling for a troll.

I'm talking about WRITING PHP code. You don't WRITE top level functions. Every data type you WRITE is a reference type.

In C++, it is common to write top level functions in a namespace for others to use. In C++ you can write a class/struct and pass it to function BY VALUE. In Java and PHP you cannot pass by value, except for primitives (which you cannot author yourself).

Your PHP code will be semantically almost-identical to a similar project in Java. Not so with C++.

Re:25 Years of PHP by jimmaswell on Wednesday June 10, 2020 @04:04PM (#23481423)
So TLF's exist and get used constantly but people don't write them often in code you look at (they do in the code I look at), you don't have to use classes and lots of pages don't but frameworks tend to stick with them, there are global variables, the syntax looks a lot more like C but class semantics exist, therefore it's exactly like Java. Whatever, if that's how you see it I guess I can't stop you.
Re:25 Years of PHP by ragnese on Wednesday June 10, 2020 @04:48PM (#23481917)
Syntax != semantics

And, even with syntax, the singular part of the syntax that looks like C is the arrow for method calls. Everything else looks like Java, including the fact that you use `struct` to group data in C, not `class`.

Also, you said C++ originally, not C. And PHP classes are NOTHING like C++ classes. They are everything like Java classes.

You're just wrong about being inspired by C++. At least in its current form.

Top level functions DO exist, admittedly. I just never see any libraries use them. I assume it's because the autoloader and composer work better with classes. What projects do you look at that use TLFs? Also, may I ask why you'd prefer them to static methods on classes (with private ctor). Isn't it less convenient to import them?

Re:25 Years of PHP by jimmaswell on Wednesday June 10, 2020 @07:04PM (#23483207)
I never said PHP was inspired by C++. There are some similarities to any language of course but to me it's closer to looking like C with classes which is where the C++ comparison came from. Not really interested in that subject anymore.

> What projects do you look at that use TLFs?

Drupal defines a lot of TLF's and I've seen user-defined ones in it sometimes. Smaller/hobby projects use them a lot.