4 ms·
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.
by ragnese 6y ago
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.
- waheoo 6y agoWhats 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.
- ragnese 6y agoWhich 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?
- leadingthenet 6y agoYou’ve convinced me never to use PHP if I can help it
- DCoder 6y agoI'd say that Symfony reads like Java, whereas Laravel reads like a weird copy of Rails.
- jimmaswell 6y agoPHP is way less verbose. I wouldn't say it really looks like Java, maybe more like C++.
- ragnese 6y agoStop 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...
- jimmaswell 6y agoAs 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?
- ragnese 6y agoI 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.
- jimmaswell 6y agoNo public code uses echo, strlen, function_exists, is_array, count, or intval? I find this really hard to believe.
- ragnese 6y agoI'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++.
- jimmaswell 6y ago