Guess why this won't work
-
Guess what's wrong with this.
if (!isset($eTag)) { header('ETag: ' . $eTag); }
-
Nope, I can't see anyt
-
-
Shouldn't it be
if(isset($eTag))
instead of
if(!isset($eTag))
?
It looks like that code will only try to consume
$eTag
only if it isn't set. Won't that result in an NRE or some other sort of crashing and burning, or at best only render an empty header value?
-
Well, yes, that's precisely the point
Starting to write
!empty
and meaning to convert it toisset
and leaving the!
is awkward.
-
Won't that result in an NRE or some other sort of crashing and burning, or at best only render an empty header value?
If warnings/notices is turned off, I think it will just print "Etag: " (well, send the header)
If print message only is on, it will print "Etag: " NOTICE: VARIABLE $ETAG NOT SET> or some BS.
If on, it will bomb.
-
Bad brace style.
-
Also, this is PHP. Exceptions, it's heard of them.
All that will happen is it will throw a warning, which may or may not be output, which may or may not be escalated to a warning handler and may or may not make it to the Apache error log.
We're talking about a header in HTTP for this, meaning that it won't actually show up except in the debug output anyway, because headers are separate to content.
-
You not a fan of Allman, or the braces for even a single line?
I'm trying to encourage my colleagues to avoid the situation that lead to Apple's goto-fail bug a bit back.
-
if ( !isset( $eTag ) ){ header( 'ETag: ' . $eTag ); }
FTFY
I'm trying to encourage my colleagues to avoid the situation that lead to Apple's goto-fail bug a bit back.
Wrong braces are always better than no braces.
Filed Under: Mostly snark, mostly
-
You can keep your K&R braces, thanks.
I'm not a fan of all the spaces everywhere, neither are my colleagues, draws the eyes to the wrong thing in our experience.
-
Was going to FTFY but can't get it to tab out line 2.
Clearly I'm doing it wrong, but it's not this difficult on other software!
-
You can keep your K&R braces, thanks.
...from my cold, dead hands...
I'm not a fan of all the spaces everywhere, neither are my colleagues, draws the eyes to the wrong thing in our experience.
Stuff is much harder for me to read without them, typically. Everything is just too smooshed together.
-
When it comes to braces, add them, then let your IDE format your code. If you're worried about what line they're on, you're Doing It Wrongâ„¢.
-
When it comes to braces, add them, then let your IDE format your code. If you're worried about what line they're on, you're Doing It Wrongâ„¢.
IDEs don't always get it right. Partly because I can't always define the rules. Partly because there's some subjectivity involved.
Filed Under: Doing the jobs that IDEs won't do
-
IDEs don't always get it right. Partly because I can't always define the rules. Partly because there's some subjectivity involved.
Filed Under: Doing the jobs that IDEs won't do
Whatever the IDEs do is right. The whitespace isn't semantic in languages like PHP, so it doesn't matter.
-
That spacing style is atrocious.
-
-
Also, this is PHP. Exceptions, it's heard of them.
You pasted no exception handling with the code, so I was guessing default behaviors.I had put that there would be a warning message print out, but I put an < around it and wasn't paying attention to notice it was hidden in the preview, so it didn't show on my post.
What actually happens depends on what level of error reporting you have turned on in the php.ini.
-
That's because there wouldn't be any exception handling. It won't throw an exception even if it in a try/catch block unless you specifically grab the error handler and force it to rethrow an exception.
PHP farts out warnings for all kinds of things, unless configuration and app environment dictates otherwise.
-
I'd go for
if (!isset($eTag)) { header('ETag: ' . $eTag); }
Or possibly without the spaces round the concatenation operator; I don't use PHP so I don't have a feel for how I'd handle it there. (However, I do put spaces around equivalent operators in other languages.)
-
psh do
[code]
!isset($eTag)?header("ETag: {$eTag}") : die("you moron why don't you check for etag correctly");
[/code]
it works...
[/sarcasm]
-
Needs more magic quotes.
-
Of course, I left the broken isset comparison so I wouldn't break regression testing.
-
The original snippet works if $eTag is set, though.
-
i suppose, for various definitions of "works". i could do
[code]
function eLog(){ ///todo: logging }
!isset($eTag)?header("ETag: {$eTag}") : eLog("you moron why don't you check for etag correctly");
[/code]
ok now we pass regression tests.
-
"Works" in the "for it to break you'd have to make assumptions" sort of way.
-
I'm glad to see you're all having fun with my faux pas *laughs*