Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6094263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:39:25+00:00 2026-05-23T12:39:25+00:00

I just spent hours trying to debug an out of memory error caused by

  • 0

I just spent hours trying to debug an out of memory error caused by the following code:

for ($i = 1; i <= 4; $i++) {
  $allowed[] = $type.'_'.$i;
}

Which PHP kindly mangles into:

for ($i = 1; 'i' <= 4; $i++) {
  $allowed[] = $type.'_'.$i;
}

This causes an endless loop, which eventually leads to an out of memory error due to appending to the array. PHP will generate a notice level error, and I could change my error reporting level to show these but I am working on a third party application which has a tendency to generate enough of these that this isn’t really a viable solution.

Is there any way to trap these really simple bugs? Ironically, if you do something like constant('i') and explicitly ask for the value it will generate a warning rather than a notice, and this behaviour would be ideal.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:39:26+00:00Added an answer on May 23, 2026 at 12:39 pm

    You could create a custom error function then filter out the most common errors and only report the less common ones. Then up the error reporting level in PHP. E.g.

    function customError($error_no, $error_message, $error_file, $error_line, $error_context) {
        $common_errors = Array('File not found', 'Another made up error', 'Its late');
        if (! in_array($error_message, $common_errors)) {
            // throw exception, log to file, or other action
        }
    }
    
    set_error_handler("customError");
    

    You could also filter errors like so:

    • Filter out all errors unless they are
      in a file of interest by testing
      $error_file against an array of
      files you maintain

    • Even better (not on a production
      server) fetch the last_modified
      date/time of $error_file with
      filemtime() and report the error if
      it was changed within the last 10
      minutes. This helps you debug code as
      you write it

    • Or if it’s within a framework which
      yours sounds like it is, break apart
      the path of $error_file and test if
      it’s in your module/view/controller
      files, as opposed to core framework
      files

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just spent hours trying to debug my code. The whole problem boiled down
I just spent the last 3 hours trying to figure out this error. I
Okay, I just spent the last four hours trying to figure out why my
I just spent 2 hours trying to find out what was wrong with my
I give up. I just spent four hours trying to figure out why this
So I just spent the last few hours pouring over code trying to figure
I just spent way too long trying to diagnose why, in the following snippet
Is there another way to do this? Just spent 2 hours trying to figure
I've just spent about 2 hours trying to get this to work. I've never
I have spent hours trying to get my project working and I just can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.