4 ms·
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'
by ragnese 6y ago
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++.
- jimmaswell 6y agoSo 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.
- ragnese 6y agoSyntax != 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?
- jimmaswell 6y agoI 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.