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...
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?
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.
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++.
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.
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?
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.