Accidentally not breaking a PHP source file
-
I'm still not sure whether I'm TRWTF on this one or whether PHP is.
I have a function that is in my current project which is borrowed from php.net (it's a bare-bones replacement for json_encode since current project is such that it uses json_encode but can't actually rely on it being available, as WordPress discovered to its cost)
So I copied the function with a link to the original post. Only I forgot the // at the start of the line.
I didn't notice it at the time, and just got on with my day. Happened to notice this today and was actually surprised that PHP didn't fail on me with a syntax error.
Then I realised why.
http://php.net/manual/en/function.json-encode.php#107968
It's treating it as a label followed by a comment. It took me far too long to realise this one. Not enough tea this morning.
-
so what would happen if you had a
goto http
call?
-
Depends where the goto is. If it's outside of the function, the goto would fail (since PHP goto cannot jump scope), but if it's inside the function it would go to that point as you would expect.
But it should be interesting to note that I have yet to write a single goto in PHP in over 11 years. In fact, this is the first time I've ever used a label in PHP and it wasn't even intentional.
-
http://php.net/manual/en/function.json-encode.php#107968
Yes! Code highlighter got it right.
-
I wouldn't call this a WTF. But I do think it's quite amusing. Perhaps funny stuff would be a better category.
-
I'm still not convinced that I'm not TRWTF ;)
-
Oh boy. Nice one, @Arantor.
-
It's a trick that I've seen used in other places too; it would work in C++ or Java for example.
-
It's a trick that I've seen used in other places too; it would work in C++ or Java for example.
People doing it on purpose is TRWTF.
-
I'm still not sure whether I'm TRWTF on this one or whether PHP is.
Or possibly both, as we all know it's likely to be PHP whether or not you are.
-
Yes but I also self-describe as a PHP enthusiast/masochist so the fact I continue to do PHP, willingly is surely some sign of TRWTFery?
-
http://php.net/manual/en/function.json-encode.php#107968
// mysql_real_http://php.net/manual/en/function.json-encode.php#107968
-
PHP isn't that bad these days. It isn't brilliant, but if this site teaches you anything it how it is abused that creates the trwtf.
-
Oh yes.
PHP has its faults and it is getting better but the worst of the worst of TRWTFery comes out of the fact that it has a very low barrier to entry and there's too many not-so-hot people getting into it as a consequence.
Programming should not necessarily be easy for a reason.