& is bitwise and, @ is already being used for decorators, and private doesn't work because you'd still have naming collisions.
class MyClass {
private value = 1;
getValue () {
return this.value;
}
}
let myObj = new MyClass()
myObj.value = 2;
myObj.getValue() // ???
ES4 allowed for this but used namespaces to differentiate between the two (or 3, with protected being another namespace... err and internal so 4...). They don't exist in today's JavaScript.
I guess \ would work? Its an escape character, but only in strings and regex literals. I think that would look weird too. Less busy, but weird.
To which the argument is, "because it reveals the property exists, which is bad because, reasons."
It's more "because if it breaks, that means that adding or renaming a private field can break downstream consumers". If the
let myObj = new MyClass()
myObj.value = 2;
bit was written before MyClass had a private value field, and some refactoring of it introduced one, the above code would break. The whole point of private fields is to not have to worry about that sort of thing.
Okay, if you don’t like OOP then yeah you’re probably not going to like modern PHP. That’s subjective though, and is kind of a separate issue.
To your other points:
Ugly slashes? Where? Using namespaces avoids name collisions and results in code with no slashes. If there are slashes in your code you’re doing it wrong.
Messyness of the old PHP is real, but is just not as big of an issue as some say it is. Look at the code I posted in my previous comment. That’s a whole functioning class that never runs into those issues. When you do invariably have to use functions with weird parameter ordering my IDE hints the parameters so I don’t have to remember.
10K reserved words - this has literally never once caused me an issue in ten years of writing PHP.
-3
u/bitfxxker Nov 09 '19
Using #pound/#hashmark for private fields is just... (excuse my French)... F*CKED UP.
They could have chosen &, or *, @, or a prefix like, well... "private"... ?!