SOLVED: Well, after two days of trying every possible fix, it turns out that when the code was copied, there was in fact a missing closing div tag in the object method. ::: face palm ::: Normally, it would be obvious from visual layout but in this particular instance everything rendered as expected. It took the comment from "Your Common Sense" to wake me up and think to count up the opening and closing div tags. Seems it was a slow insidious buildup that wasn't creating a big enough stack to crash firefox (but with enough records eventually would have) Doh! Thanks for all the comments guys! I'm going to go crawl under a rock now. :)
This issue only happens in Chrome/Edge but NOT in Firefox, and I'm really stumped on this one.
I'm in the process of converting a very large web project over from "linear" php code into "object oriented" php code. Everything has been transitioning smoothly up to this point, but here's the situation.
In my original code, I had a php page which reads a bunch of records from the database, and then does the traditional loop through the SQL objects to grab the data from each record, and formats them in a nice output using tags, etc. with a bunch of echo statements. Something like this simplified example:
$sql = "...query syntax...";
$result = conn->query($sql);
while ($row = $result->fetch->object) {
echo "<div>".$row->parameter."</div>" // etc.
}
It was fairly complex formatting but worked perfectly and could handle thousands of records without any hiccups. My test run query is pulling about 1 500 records, but it's worked with over 10 000 records.
In my new object oriented version, I created a Record object that handles all of the database queries and outputs the formatting as an html code block. I call it like this:
$record = new Record();
$record->load(); // loads the record from the database
$record->draw(); // outputs the final formatted data
Again, this works exactly as expected no problem there. So here is where it gets interesting. The Record object only handles a single record. So I created a RecordList object which is essentially an array of Record objects (with a bunch of methods for handling searches, different queries, etc), sometimes as much as a few thousand records. I have a method which returns one record at a time from the RecordList object so it is used like this:
$list = new RecordList();
$list->load(); // loads a bunch of records (also 1500 records)
while($record = $list->get_next_record()) {
$record->draw();
}
When I attempt to run this code, it will output up to 389 records, but on the 390th call the browser throws the full screen STATUS_STACK_OVERFLOW error. Happens on Chrome and Edge. I have tried outputting the memory after each call and I'm never more than 5MB of usage so it's not an out of memory error, and I don't have any recursive calls in my methods that I can find. Additionally, it's important to note that it's not something in the data itself...I'm testing it with a live database so the content of the records changes every time I run my code.
I've tried including a flush(); after each draw in my Record object as well, but it doesn't seem to help.
It's probably worth noting that I just copied the "echo" statements from my original code and pasted them into a method called "draw()". I'm planning on upgrading that to build the entire format in a variable called $output and then display it with a single Echo statement before exiting the method. Not sure if this might be at least partly causing the issue, but wanted to mention it just in case.
I'm kind of at a loss as to where the problem is, especially considering it is only happening with my Object Oriented version.
Shockingly, this is the first time I've ever encountered a problem with the stack in 5 years working on this project so I'm not really sure how to proceed.
I'm kind of at a loss as to where the problem is, especially considering it is only happening with my Object Oriented version.
Shockingly, this is the first time I've ever encountered a problem with the stack in 5 years working on this project so I'm not really sure how to proceed.
I'd suggest to relate to the definition of refactoring by Fowler (IIRC), and it's something like change of code but it must change nothing on the outside.
Your browser, clearly the outside, has shown you a change.
This simply means that the refacoring you did was wrong.
I'd revert to last known good and see comparing the two if it shines (e.g. git bisect to find the culprit).
Then I'd analyze what happened there and adopt the refactoring strategy accordingly. Maybe on one part linear before had the right strategy for a component, but you applied object orientation with a shotgun on the code and made no prisoners.