Reputation: 7424
Is it possible to change the object operator "->" to ".", so accessing class methods would look like that: $user.add()
instead of $user->add()
?
I guess that this is not a very smart question, but you have to agree, that when you type "->" You have two symbols for one of which you have to press SHIFT which is ways more complicated then ".". And the dot looks prettier.
Upvotes: 0
Views: 170
Reputation: 17879
Basically PHP is open source, so you can get the source code and modify as you wish. But in the reality such a modification is a bad idea because of a couple of reasons:
Your primary idea is not bad to replace these two chars by one, but you see that these changes will be result in some other problems, which are not in a relationship to the time you save with this modification. I'm myself a PHP-Developer and I can tell you that using -> instead of a dot will confusing you at the beginning, especially when you're comming from other languages like Java or C# which are using the dot.
But after writing some code you get familiar with these type of syntax and it shouldn't be a problem any more. You can put your forefinger of your right hand on the '-' key, your little finger on the shift key right of the minus and the little finger of your right hand to the '|' key. Then it will not cause you much overhead to type a -> instead of a dot :)
Upvotes: 1
Reputation: 10413
I'd guess that this is not possible since .
is used as concatenating operator. Where would we be if everyone could change these things, the language would be very unstable I guess.
So: nope.
Upvotes: 5
Reputation: 91912
It may be possible to do that by changing the code parser. You will of course need to test this carefully and then recompile PHP. You cannot do this from within PHP, only by rewriting the C source code.
Upvotes: 6
Reputation: 382686
No you cant do that, it comes from the core of the language you cant change. AFAIK certain other languages use that too, PHP stood by the convention.
Upvotes: 4
Reputation: 318488
No, that's not possible. Probably even by modifying the language's grammar it would be extremely hard since it could cause ambiguity - $foo.bar()
could then either be a method call or concatenating $foo
and the return value of bar()
.
Use a different language if you do not want ->
. My suggestion would be python - it's much saner than PHP anyway.
Upvotes: 9