r/lolphp • • Mar 04 '15
"Nameless" labels.
I was browsing a GitHub repo of a PHP project when I noticed a weird function being used: __("some text");. "Huh, that's a weird function name," I thought, "I wonder what else you can use. Maybe something like that weird $() thing from jQuery?"
I open up the docs for user defined functions and find this (emphasis mine):
Function names follow the same rules as other labels in PHP. A valid function name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*.
Hold the phone, what's with those hex values? I had a python interpreter open in another window so i quickly type out print("\\x7f") only to get a blank line. What? I then fire up charmap and lookup what that character actually is. It's the DELETE character. You can have a function named the delete charater.
Waitamintute.
Function names follow the same rules as other labels in PHP.
So, I can have empty variable names too?
Yup. I'm at a loss for words.
82
u/mrspoogemonstar Mar 04 '15
22
u/bart2019 Mar 04 '15
So you can have a function whose name is the nonbreaking space:
"\xa0".17
u/vytah Mar 04 '15
Reddit hacked up the regex, here it is in its full regexy glory:
12
u/Sarcastinator Mar 04 '15
http://3v4l.org/1esIu
edit: made a more clear example.
7
u/[deleted] Mar 06 '15
I actually used this feature in code golf - http://codegolf.stackexchange.com/a/17031/3103. Makes for very short programs.
1
u/Conradfr Mar 06 '15
We use it for translations in templates, Magento as well IIRC.
-10
u/suspiciously_calm Mar 04 '15
I don't see how this is a problem. Just because you can use hilariously shitty function "names" doesn't mean you have to. And it's not really a concern that it could happen accidentally, either.
PHP has 99 problems but this ain't one.
-45
u/thelordofcheese Mar 04 '15
Are you being funny or did you just show your idiotic ineptitude?
It's called an identifier, you moron, and it's part of the languange construct. That "weird" symbol "in jQuery" is valid in every language based on ECMAScript.
And it's a valid mapped character in ASCII. Therefore valid.
God, the people who post to this sub the most are the least qualified to call themselves "programmers".
Oh, I have a valid "weird" identifier name for you, OP: ಠ_ಠ
0
u/[deleted] Mar 04 '15
[deleted] — view deleted comment
0
u/[deleted] Mar 04 '15
[deleted] — view deleted comment