- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
How does PHP deal with integer overflow? Error? Exception? Silently?
Admin
Admin
By turning it into a bowl of petunias.
Admin
This topic is now listed. It will be displayed in topic lists.
- At least the linking seems to work.
Admin
And while we're on the subject of integer overflow and PHP - and for those that haven't seen it yet - this is talking about the source code to PHP:
http://use.perl.org/use.perl.org/_Aristotle/journal/33448.html
It starts off with:
and goes downhill from there.
Admin
I actually had to write a progress bar in PHP yesterday... I don't think my solution is as elegant as their idea though.
Admin
The only WTF here is that a series of "if"s are being used to construct, what is in effect, a 7 bar LED display for use elsewhere.
That the code is PHP is immaterial. That $count may or may not cause an integer overflow is equally immaterial.
Because this is just a snippet of code within "something" else that will deal with integer overflows, and places to which 7bar LED displays can be shoved, etc etc.
The only thing that could be a real WTF of the minor WTF (that this story is), that the 7bar LED is not scalable or mutable. But then it may not need be -"... we have 7 spare pixels / lights / blobs, let's do a quick progress bar..."
Admin
More importantly, is the threshold for strangeness portable? Spoiler: nope!
Admin
However, on further analysis, assuming the sample is complete:
$count never gets to 50. $dots never gets constructed let alone displayed
Even if "something" loops this snippet, the above holds true because $count gets reinitialised.
Admin
Everyone is so focused on overflow and other possible WTF's that I think the obvious was overlooked: $dot will be set to "." and that's it...for the whole life of the task.
EDIT: Except, of course, for @loose, who posted just before I did (1-2 minutes) while I was scrolled to the top where I didn't see his message.
Admin
:unamused:
:wink:
Admin
Well, sorry, Your post appeared while I was writing and ...scrolled up toward the top of the messages. I didn't see it until after I posted. So much for the Discourse communication model, huh?
Admin
I know, that's why the wink.
And yeah. I have that problem too 'cos I'm looking at the keyboard and not the screen.
Admin
Could running in a separate thread, not stated in the article. And its state could be what's inside $task which could be set to false when the task finishes.
Admin
Huh? It's initialized to 0 before the while loop.
I assume the snipped content is something like
What doesn't work is that
$count
is = 50 only once then, instead of being zeroed when it's equal to 50, so dots get constructed only once (and obviously, the display code is missing). Guess it's a line too many being snipped.Filed under: good old dots 1.0
Admin
Maybe we should ask @remy for the original code?
Admin
@Samuel_Schoenberg, you can come out now, we know it's you.
Admin
That'd be one hell of a front page troll. I approve!
Admin
Whilst PHP can make system calls etc. It has to wait for them to complete - one of the many reasons for blank white screens in PHP Web Servers.
To prevent the (PHP) world coming to a grinding halt, it has a settable maximum script execution time. But, this can be set to "forever" and it, perversely, does not account for time taken for system calls: Just internal operations like DB queries and array iterations and the like.
That aside: If run the task is 1337 WTF commenting for take a peek at task and see how it is doing. Then, yeah. You have a potential infinite loop situation where the programming language's ability / methods to deal with integer overflow, could vastly alter the final result.
@CoyneTheDup Ummm.... Looks like you were right. Somehow overflowing integers have become core to the topic.
Admin
In PHP? Not likely.
But the exit condition sure is weird. Then again, PHP, given the quality of most PHP code, who knows what's happening there. Maybe
$task
is a poorly named array of tasks, getting cleared as each one is finished?if(array())
evaluates toFALSE
in PHP...Admin
Yes. $count will only ever be 50 once. In passing, so to speak, as it rapidly accelerates to INT_OVERFLOW / INFINITY / FILE_NOT_FOUND.
Didn't I say that?
Admin
I'm pretty sure I've written something similar to this before, though it wasn't in PHP...
Admin
An array with zero elements will be evaluated as FALSE
Admin
Yes and,
===
evaluates to
TRUE
.And that, children, is how boolean logic works...
Admin
I think :sweat: ... I see what you did there. :relieved:
Good job I'm not impulsive and respond immediately and violently to Trolls. Real or imagined. :laughing:
Admin
Multi-threaded PHP? Is that a thing? (If it is, please pass the valium/strychnine mix…)
Admin
I have just realized: We have a catch 22 here.
While task is running true, Schrodinger's progress indicator may or may not tell us it is running. But, as $task is started after entering the loop, it is by definition false SO.....
$task will never enter the loop, but we can't be sure if it has or has not
Perhaps TRWTF is that the WHILE loop should be a DO loop.
Admin
I'm sure someone tried a creative hack to make it kinda possible already, since Apache (and presumably nginx) will run multiple PHP scripts in separate threads. You can't use that in your own PHP code, of course, but you do have
exec
... and PHP CLI...I better stop now before I get tempted...
Admin
I have dallied here too long. I have a meeting in 30 mins to present some proposals for some changes to code that need modernising but cannot be changed. And I need to doo three things to prepare myself:
Admin
Well, there's popen. And proc_open.
Admin
I have used them. But your script had better be better than immortal otherwise it dies an orphan and sooner or later there is no room left in the cemetery.
Admin
You just need a zombie reaper. Duh!
Admin
FTFY
:hanzo: Oh disgorge.
Admin
lern2touchtype n00b!
Admin
This is what happens when you let Visual Basic programmers design languages.
Admin
Personally I'm sympathetic because while I used to be able to touchtype I now have to be able to cope with English and Russian keyboards in more than one size, and virtual keyboards. It may be possible to touchtype on a glass keyboard, but not by me it isn't.
Admin
You can just talk to the MCP program from that console, so the keyboard's kind of redundant.
Admin
The Master Control Program Program? Is that what you use when you type your PIN number into the ATM machine?
Admin
I didn't write the fucking screenplay, go away and leave me alone.
Admin
PHP has had a pthreads extension for a very long time, though I haven't used the new OO version (which, surprise surprise, looks a lot like Java's).
Admin
I read it as the "Male chauvinist pig program". That's an AI that tries to keep women out of software engineering, probably by making disparaging remarks about their typing skills.
Admin
http://www.cnn.com/2015/06/10/europe/hunt-women-scientists/
Admin
It occurs to me that the (previously withheld) information that I have a 22" 10 point Touch Screen, and make occasional use of the screen keyboard. Could put a different spin on my relpy :stuck_out_tongue:
Admin
IIRC there were plenty of female characters in the computer world.
Admin
Good grief! What on earth are they doing in there? The options are:
I'm guessing that they've gone for the C way. Because we're talking PHP and that can deliver by far the greatest :wtf: factor…
Admin
Quoted For Serious Truth -- why is it that people seem to have this misguided belief that threads are the One True Way to Parallelize?!?! (Hint: *nix systems did parallelization way before they got threading.)
Admin
There are cases where shared-memory threading is useful, such as some of the really heavy math processing we need at work when extracting the sense out of the data read off the lab instruments. Most people don't hit those cases. :smile:
Admin
Threading is actually the best way to parallelize. It just doesn't work well because software developers write code that is too dependent on each other. If everything were developed in a more independent manner, such as spawning a new instance of a database for every each thread. Then we could fully utilize parallel computing via threads.
Admin
You clearly have not had to bust out Helgrind on a threading bug before...
(I agree with you re: we need more parallel code -- but threads have far too many footguns attached to them to be anywhere near the "best" way to do it. Hint: if you spawn a thread and it then proceeds to get itself hosed in an unrecoverable way, what do you do about it?)
Also, FPT :warning:
Admin
Threading bugs are a complete COMPLAIN. Seriously awful. They're bad enough when those threads are in different processes (so at least the threads aren't stomping on each others' toes directly) but that's nothing by comparison with what happens when two threads that share memory decide to do a number on each other.
What's more, most programmers have had no idea that threads were such a dangerous tool until pretty recently. That's because it's only recently that we've started to see true multicore systems become widespread. Emulating by context switching on a single CPU core is not the same at all; for one thing, when emulating you at least keep consistency between the CPU and the memory, even if not what the program was expecting. With real multicore systems, you lose that. Happy Fun Times ensue! :anguished: