Sometimes I am TRWTF.
-
So I'm finding that one page of a site I'm working on, hangs. It only happens locally, not online (thank goodness). I'm working with PHP4 so I can't get XDebug and stuff, this is legacy code so no logging or anything. So what do I do? I put an exit('test'); statement in and move it around. Finally, I come to the point where I find out that this doesn't hang:
exit('test'); if (extension_loaded('curl')) { // do stuff } else { // do other stuff }
And this does:
if (extension_loaded('curl')) { exit('test'); // do stuff } else { // do other stuff }
My conclusion: HOLY SHIT the extension_loaded function hangs my site! So I spend about half an hour googling, before realizing the problem is inside the else clause. Can I hand my programming license please? :(
-
@toon said:
PHP4
TRWTF. Unsupported for at least 5 years, maybe even 13 years.
PHP is bad enough but am ancient one would drive me to ragequit life!
-
@Zemm said:
@toon said:
PHP4
TRWTF. Unsupported for at least 5 years, maybe even 13 years.
PHP is bad enough but am ancient one would drive me to ragequit life!
Unfortunately, I'm stuck with PHP 4 for many legacy projects. I actually think 5.2, which our PHP 5 projects use, is old. All the cool PHP people are doing stuff with namespaces. Can't do that with 5.2. If it were up to me, we'd switch to 5.4 or even 5.5.
-
@Zemm said:
PHP
TRWTF.
-
-
Turn on output buffering
ob_start();
then add between every line:
echo (LINE)."<br/>";ob_flush();
to get the line number that worked to print out.
Of course, for the most likely cause of a "hang"- infinite loop will give you a whole lotta numbers.... but at least you'll see where it repeats.
Quote from the PHP docs below... I love magic!
A few "magical" PHP constants
LINE : The current line number of the file.
-
@darkmattar said:
Turn on output buffering
LINE : The current line number of the file.
Hmm, is this just an old VB thing? I remember a VB LineNo variable that did the same thing and you had to debug the same way. Please someone send me to total recall and wipe that memory and replace it with something pleasant.
-
@KattMan said:
@darkmattar said:
Turn on output buffering
LINE : The current line number of the file.
Hmm, is this just an old VB thing? I remember a VB LineNo variable that did the same thing and you had to debug the same way. Please someone send me to total recall and wipe that memory and replace it with something pleasant.
No idea, never created any VB code myself.
Also, add FILE to the echo if you want the file name that line number is referencing, in cases where you have a mess of include nests.
-
@KattMan said:
@darkmattar said:
Turn on output buffering
LINE : The current line number of the file.
Hmm, is this just an old VB thing? I remember a VB LineNo variable that did the same thing and you had to debug the same way. Please someone send me to total recall and wipe that memory and replace it with something pleasant.
Recall creates new memories, you need Lacuna, Inc. to delete them.
-
@KattMan said:
@darkmattar said:
Turn on output buffering
LINE : The current line number of the file.
Hmm, is this just an old VB thing? I remember a VB LineNo variable that did the same thing and you had to debug the same way. Please someone send me to total recall and wipe that memory and replace it with something pleasant.
I've used it regularly during my C++ days
http://stackoverflow.com/questions/597078/file-line-and-function-usage-in-c
-
@bjolling said:
@KattMan said:
@darkmattar said:
Turn on output buffering
LINE : The current line number of the file.
Hmm, is this just an old VB thing? I remember a VB LineNo variable that did the same thing and you had to debug the same way. Please someone send me to total recall and wipe that memory and replace it with something pleasant.
I've used it regularly during my C++ days
http://stackoverflow.com/questions/597078/file-line-and-function-usage-in-c
__LINE__ and __FILE__ go clear back to C. Maybe farther. They've been part of the standard for a very long time.
-
Sometimes I really am TRWTF:
Fail #1, Severity: Minor - I had misclicked on the taskbar and hit SQL Server instead of the program I had wanted to open.
Response: I have been able to open the Task Manager to kill an accidentally started process before its window come up and becomes responsive enough to actually be able to exit from the close button.
Action: Opened Task Manager, sorted processes by name, scrolled down to 'S', selected the process, and clicked the End Process button.Fail #2, Severity: Major - Well, just look:
The checkbox starts out cleared and Shut down is greyed out, but I looked at the message, marked the checkbox, and then clicked Shut down, expecting that SQL Server would be shut down.
Response: The moment I clicked the button, my computer blue-screened and started dumping the RAM to disk. I instantly realized that I must have mis-selected the wrong process.
Action: I waited for the crash dump to finish and the computer to restart. When I logged in, I reopened the Task Manager to see what exactly I had killed.Conclusion: SQL Server Management Studio has the process label "ssms.exe", but the Windows Session Manager runs under the process name "smss.exe", and the latter is necessary for the system to run properly.
-
@djls45 said in Sometimes I am TRWTF.:
Windows Session Manager
Wow, Windows got stupider since Windows 7, apparently...
-
@tsaukpaetra said in Sometimes I am TRWTF.:
Windows got stupider since Windows 7
I don't think this surprises anybody here.
-
@scarlet_manuka said in Sometimes I am TRWTF.:
@tsaukpaetra said in Sometimes I am TRWTF.:
Windows got stupider since Windows 7
I don't think this surprises anybody here.
I was practicing my external Captain Obvious mode.
-
@djls45 said in Sometimes I am TRWTF.:
Conclusion: SQL Server Management Studio has the process label "ssms.exe", but the Windows Session Manager runs under the process name "smss.exe", and the latter is necessary for the system to run properly.
That is a shockingly small "cognitive distance" between those two, given the consequences of picking the wrong one.
-
@tsaukpaetra said in Sometimes I am TRWTF.:
@djls45 said in Sometimes I am TRWTF.:
Windows Session Manager
Wow, Windows got stupider since Windows 7, apparently...
Depends. What happens if you actually terminate it? Does the machine wobble a bit, or does it blue-screen immediately?
-
ssms.exe, smss.exe, ssds.exe...eh it's all the same thing.
-
@djls45 It took me a long time to realize they are spelled subtly different.
This immediately comes to mind:
-
@tsaukpaetra said in Sometimes I am TRWTF.:
@djls45 said in Sometimes I am TRWTF.:
Windows Session Manager
Wow, Windows got stupider since Windows 7, apparently...
You mean, it made stupid mistakes harder to do? I don't agree with that meaning, but if that's the commonly accepted definition of "stupid" in 2018, so be it. Personally, I prefer my system to be as stupid as possible, and I always try to make my applications to be so stupid that you can't ever break them.
-
@mott555 There's also sdss.exe
-
@steve_the_cynic said in Sometimes I am TRWTF.:
@tsaukpaetra said in Sometimes I am TRWTF.:
@djls45 said in Sometimes I am TRWTF.:
Windows Session Manager
Wow, Windows got stupider since Windows 7, apparently...
Depends. What happens if you actually terminate it? Does the machine wobble a bit, or does it blue-screen immediately?
Immediate death.
-
@gąska said in Sometimes I am TRWTF.:
You mean, it made stupid mistakes harder to do?
No?
The one in Windows 7 was harder to screw your system, because it has a special dialog with an extra checkbox in an unusual place that's not covered by middle muscle memory. Windows 10 (and presumably 8,can't be bothered to check) uses the same "you just want to kill that? Could be dangerous, could be not!" box for everything.
The only protection now is a "access denied" message, which is even stupider since now there's not even an explanation as to why you might not want to do that.
-
@tsaukpaetra fuck, I messed up which one is 7 and which is 10.
-
A well-meaning local civil servant caused the unspeakable devastation when he attempted to cast the ZEMDOR spell (“turn original into triplicate”) but, instead, accidentally cast the ZIMBOR spell instead (“turn one really big city in lots of tiny, little ashes”)
It's the user's fault, magic was just doing what he told it to do. WONTFIX.
-
@toon said in Sometimes I am TRWTF.:
Unfortunately, I'm stuck with PHP 4
Four years later and someone used a
??
in our PHP code. The dev boxes are officially running PHP 5.6, with production on 7.0 (don't ask), so some devs upgraded their manually. This dev then proceeded to use a 7.0+ feature. But it was used likereturn $something['val'] ?? null
. WHAT? If it's null, return ... null?
-
@zemm said in Sometimes I am TRWTF.:
@toon said in Sometimes I am TRWTF.:
Unfortunately, I'm stuck with PHP 4
(don't ask)
But... but... but... that's probably the best part of the story!
-
@zemm said in Sometimes I am TRWTF.:
@toon said in Sometimes I am TRWTF.:
Unfortunately, I'm stuck with PHP 4
Four years later and someone used a
??
in our PHP code. The dev boxes are officially running PHP 5.6, with production on 7.0 (don't ask), so some devs upgraded their manually. This dev then proceeded to use a 7.0+ feature. But it was used likereturn $something['val'] ?? null
. WHAT? If it's null, return ... null?Only one way to be sure...
-
@zemm said in Sometimes I am TRWTF.:
@toon said in Sometimes I am TRWTF.:
Unfortunately, I'm stuck with PHP 4
Four years later and someone used a
??
in our PHP code. The dev boxes are officially running PHP 5.6, with production on 7.0 (don't ask), so some devs upgraded their manually. This dev then proceeded to use a 7.0+ feature. But it was used likereturn $something['val'] ?? null
. WHAT? If it's null, return ... null?Given it's PHP my first thought was "what else will that operator work on besides
null
?" Looking at the proposal and new features notice I'm guessing it also handles whatever happens when a thing it's operating on doesn't exist (exception?).
-
@tsaukpaetra maybe it's there to make it not compile on anything older, forcing an update for everyone?
-
@dreikin yeah, it could be whatever coerces to falsey.
-
@pie_flavor said in Sometimes I am TRWTF.:
@dreikin yeah, it could be whatever coerces to falsey.
I found this and modified it slightly to this. Falsey values don't mess it up, but it does silently handle the case of using an undeclared/unset variable.
-
@gąska said in Sometimes I am TRWTF.:
maybe it's there to make it not compile on anything older, forcing an update for everyone?
It was there because the dev didn't understand what that operator was supposed to be used for.
There's an official dev box image "coming soon" (which is also an upgrade from CentOS 6.x to 7.x) which is supposed to be mostly built from the same puppet repos as production.
@pie_flavor said in Sometimes I am TRWTF.:
yeah, it could be whatever coerces to falsey.
That's what
?:
is for. Which is in PHP 5.6.@the_quiet_one said in Sometimes I am TRWTF.:
But... but... but... that's probably the best part of the story!
I wasn't aware of the reasons, it might have even been a mistake, because the brand-new code is 7.0+, but there are separate clusters for each so it could have been separated. I mostly work on the legacy-legacy Perl code. (Perl 5.10.1 FTW!)
@dreikin said in Sometimes I am TRWTF.:
but it does silently handle the case of using an undeclared/unset variable.
No it doesn't: https://3v4l.org/q1Gkv
It still issues a Notice around the undefined index.
-
@zemm said in Sometimes I am TRWTF.:
I wasn't aware of the reasons, it might have even been a mistake, because the brand-new code is 7.0+, but there are separate clusters for each so it could have been separated. I mostly work on the legacy-legacy Perl code. (Perl 5.10.1 FTW!)
@dreikin said in Sometimes I am TRWTF.:
but it does silently handle the case of using an undeclared/unset variable.
No it doesn't: https://3v4l.org/q1Gkv
It still issues a Notice around the undefined index.
No? It issues a notice when you use the undefined index without the null coalescing operator (as expected), but the ones using it are silenced.
-
@zemm said in Sometimes I am TRWTF.:
That's what ?: is for. Which is in PHP 5.6.
Yeah, but that's wrong-associative.
-
@pie_flavor It's PHP; of course it's wrong.
-
@dreikin said in Sometimes I am TRWTF.:
No? It issues a notice when you use the undefined index without the null coalescing operator (as expected), but the ones using it are silenced.
Whoops. https://3v4l.org/Qvb3C - I now understand my misreading. :)
@pie_flavor said in Sometimes I am TRWTF.:
Yeah, but that's wrong-associative.
You're talking about the ternary operator
? :
. There is a literal?:
in PHP called the elvis operator (which is||
in Javascript or Perl) that will return the left side if it's "truthy" or the right side if the left side is "falsey".So it's similar to null-coalesce but false values in the left side like
0
or''
will return the right side.a() ?: b() ?: c()
short-circuits sob()
will only be called ifa()
returns something that is false in PHP (likefalse
,0
or''
, etc). Same:c()
will only be called ifb()
is called and is falsey. Ifa()
returned say a5
then the other two functions will not be evaluated and the expression will return 5.In PHP
||
will always return a boolean. Soa() || b() || c()
has the same associativity. But in the case ofa()
returning5
the expression will betrue
.