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 7183119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:54:55+00:00 2026-05-28T17:54:55+00:00

When the interpreter reaches $pDB->AddLine(5,Test) it stops responding! It returns the following error Fatal

  • 0

When the interpreter reaches $pDB->AddLine(5,”Test”) it stops responding!
It returns the following error “Fatal error: Maximum execution time of 30 seconds exceeded in … on line 21” Am I missing something? Should I use array_push() instead?

<?php
    class pDb{
        protected $m_pArray;
        public function __construct($arr){
            $this->m_pArray = $arr;
        }
        public function RemoveLine($index){ // Todo
        }
        public function ReplaceLine($index,$input){
            if(!$this->m_pArray)return -1;
            $temp = array();
            for($i=0;$i<count($this->m_pArray);$i++){
                ($i == $index) ? $temp[$i] = $input : $temp[$i] = $this->m_pArray[$i]; 
            }
            $this->m_pArray = $temp;
        }
        public function AddLine($index,$input){
            if(!$this->m_pArray)return -1;
            $temp = array();
            for($i=0;$i<count($this->m_pArray);$i++){
                if($i == $index) { $temp[$i] = $input;$i = $i-1; }else{ $temp[$i] = $this->m_pArray[$i]; }
            }
            $this->m_pArray = $temp;
        }
        public function Get(){ if($this->m_pArray)return $this->m_pArray; return null;}
        public function GetLine($i){ if($this->m_pArray)return $this->m_pArray[$i]; return null;}
    }

    $file = file("db.ini");
    for($i=0;$i<count($file);$i++){
        echo $i.": | ".$file[$i]."<br/>";
    }

    echo "<br/>===================================================================================================================<br/><br/>";

    $pDB = new Pdb($file);
    #$pDB->ReplaceLine(5,"Test"); // Works!!!
    $pDB->AddLine(5,"Test"); // Crash!!!
    for($i=0;$i<count($pDB->Get());$i++){
        echo $i.": | ".$pDB->GetLine($i)."<br/>";
    }
?>

Fix :
Change

for($i=0;$i<count($this->m_pArray);$i++){
                if($i == $index) { $temp[$i] = $input;$i = $i-1; }else{ $temp[$i] = $this->m_pArray[$i]; }
            }

to

        $done=0;
        for($i=0;$i<count($this->m_pArray)+1;$i++){
            if($i == $index && $done!=1){ $temp[$index] = $input; $done=1;}elseif($done == 1){ $temp[$i] = $this->m_pArray[$i-1]; }else{ $temp[$i] = $this->m_pArray[$i]; }
        }
  • 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-28T17:54:56+00:00Added an answer on May 28, 2026 at 5:54 pm

    Consider your code…

    for($i=0;$i<count($this->m_pArray);$i++) {
      if($i == $index) {
        $temp[$i] = $input;
        $i = $i-1;
      } else {
        $temp[$i] = $this->m_pArray[$i];
      }
    }
    

    If $i == $index, then you promptly subtract one from $i, and go around the loop again. This adds one to $i, making it equal to $index again, and you fall into the same case – forever! You either need to tie your loop condition to something you change in the if branch (i.e. $temp), or change the logic here completely.

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

Sidebar

Related Questions

My Python Interpreter (v2.6.5) raises the above error in the following codepart: fd =
My ruby interpreter is crashing on almost every page request with the following error:
I'm building an interpreter and as I'm aiming for raw speed this time, every
In my interpreter, code like the following x=(y+4)*z echo x parses and optimizes down
I am creating an interpreter for my extension to HQ9+, which has the following
At the IDLE interpreter I do the following with dpkt: for ts, buf in
I need a simple interpreter which will do execution (evaluation) of simple expressions/statements and
I'm writing an interpreter for an experimental language. Three of the main constructs of
In MySql's interpreter, it's very easy to dump a table to the screen along
I updated my python interpreter, but I think the old one is still called.

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.