Why is PHP displaying numbers instead of including the file?

I've encountered an unusual issue with my PHP web application. I have structured it to be modular, breaking down the code into smaller files to keep it manageable. The app serves as a fund application management system for a nonprofit organization, and one problematic module calculates and displays the number of business hours since an application was submitted.

This specific "time" module is utilized in various sections of the application. While it functions correctly in most instances, there is one area where it fails to execute properly, instead displaying the number "12". Is this potentially due to my code being too complex, causing PHP to exceed its memory limits?

The "time" module:

<?php
/* Time Module
Added for Version: 1.1
Last Updated: 10/11/2012
*/

$timeSince = time() - (int)$item['timestamp']; //Calculate seconds between current time and submission
$timeSince = $timeSince / 60 / 60; //Convert seconds to hours
$timeSince = round($timeSince); //Round up or down

if( //Set color to green within review timeframe
($timeSince <= 12 && $item['appStatus']=="0") ||
($timeSince <= 48 && $item['appStatus']=="1") ||
($timeSince <= 72 && $item['appStatus']=="2")
)
    $timeColor="#090";
elseif( //Highlight yellow if slightly behind
($timeSince <= 24 && $item['appStatus']=="0") ||
($timeSince <= 60 && $item['appStatus']=="1") ||
($timeSince <= 84 && $item['appStatus']=="2")
)
    $timeColor="#F90";
else //Red if far behind
    $timeColor="#F33";
?>
Submitted: <?php echo date("F j, Y", $item['timestamp']) ?><br>

<?php if($item['appStatus']=="0" || $item['appStatus']=="1" || $item['appStatus']=="2") { ?>
<span style="color:<?php echo $timeColor ?>"><?php echo $timeSince ?></span> Hours Since Submission
<?php } ?>

Location in the code where the file is included (under action buttons):

<div style="float:right; padding:10px; text-align:right;">
<?php if(isset($includePrefix)) { ?>
    <a href="appAssets/print.php?id=<?php echo $_GET['id'] ?>" target="_blank">
    <img src="appAssets/print.png" alt="Print This Application" align="middle" title="Print This Application" /></a>&nbsp;

    <a href="mailto:<?php echo $item['agencyEmail'] ?>">
    <img src="appAssets/email.png" alt="Email Agency" align="middle" title="Email Agency" /></a>

    <?php if(!$hide) { ?>
        <a href="#" id="disbursementLink">
        <img src="appAssets/dollar.png" alt="Disbursment Instructions" align="middle" title="Disbursement Instructions" /></a>
    <?php } ?>
    <br />
<?php } ?>

<?php include_once("time.php") ?>
</div>

Answer №1

When PHP runs out of memory, it triggers a specific "Out of memory" fatal error. It seems unlikely that your scripts are causing this issue since they don't involve memory-intensive tasks like image or video processing, or loading large sets of SQL data.

If you're not receiving the error message but instead getting an unexpected output (e.g., 12), it's possible that your error reporting is not enabled:

error_reporting(E_ALL); // set to desired error level
ini_set('display_errors', TRUE); // show errors in the browser
ini_set('scream.enabled', TRUE); // disable error suppression with '@'

If there are no errors (excluding notices and warnings), then your code is likely functioning correctly. The challenge may lie in aligning how the code is written with its intended functionality.

In a procedural programming approach, variables are global and persist beyond their original scope. This can lead to confusion as a variable may retain its value from a previous execution, causing unexpected behavior when accessed later on.

Answer №2

After enabling error reporting, I discovered that there was an unexpected inclusion of a file named "time.php" located in the root directory of the site. This particular file was actually a test script I had developed to calculate business hours between two dates. It generated an output of "12" as it calculated the time span between the specified test dates.

My web application consists of a complex structure with nested includes across different directory levels, leading PHP to follow specific rules in this scenario. Since the main script execution initiates from the root directory of the site, it first searches for files there before moving on to subdirectories (the "time" module being included from another module situated within the "modules" subdirectory). As both the site root and modules directory contained a "time.php" file, PHP prioritized the one located in the root directory.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

There appears to be a disconnection issue with the PHP Zend Framework 2 and

Hey there, I have a PHP daemon set up to manage requests from RabbitMQ. However, after running for a day, it stops functioning due to encountering the error "MySQL has gone away." PHP Warning: PDOStatement::execute(): MySQL server has gone away in /var/ ...

If a quote character is detected in a string, color the line red

My goal is to highlight each line from a string in red if it contains the ">" character. I am applying this logic to a database query result, and while it's successful, I'm encountering an issue where an HTML line break is inserted after each "qu ...

ajax.php form connected to a database using php

Introduction: I am currently working on a server-side datatables library. The code snippet below is not displaying either $stmt or $row, making it difficult to identify the issue. It's frustrating because I was hoping to troubleshoot this without see ...

Finding keywords in a string present within an array: A step-by-step guide

In my scenario, I am dealing with a string that has a maximum of 200 characters and an array containing 4000 elements. Each element in the array is unique and may consist of up to three words. The main objective is to extract all keywords from the string ...

Difficulty organizing form inputs into arrays prior to submitting them through AJAX

I am currently developing a complex multi-step form that involves various sections such as Company, Job Site, Contact, and Product. My goal is to efficiently gather the form data either as an array or object before converting it into a string for transmiss ...

What is preventing me from connecting to the BoM FTP server using PHP?

I'm facing difficulties in transferring an XML file from the Bureau of Meteorology (Australian) Public Access Data Feeds to my server using PHP. Despite being able to access the file through a browser, I am unable to interact with it using PHP through ...

Having difficulties grasping the concept of how to communicate effectively with my MySQL database

Apologies in advance for asking a question that may have been answered elsewhere, but I've been struggling for hours to transfer the information into my own program. Despite my attempts, I always encounter the same obstacles. So, I decided it would be ...

Ways to showcase a directory and its files in PHP with the ability to download the files

As I embark on the journey of setting up a file server, The basic idea is to have multiple folders containing files that users can download by clicking on them, and if it's a folder, they can navigate inside to see its contents. I'm currently g ...

The function password_verify() consistently yields a negative result

As a beginner, I recently attempted to develop a login system using PHP and MySQL. I successfully created a registration form and added a few users, but encountered issues when trying to create the login form. Every time I tried to log in, it displayed an ...

Issue with anchor tag not functioning properly within toggle div

Can you please help me troubleshoot why the anchor tag is not functioning properly within my div elements? When I click on the first div, the second div is displayed but the anchor tag inside the first div does not seem to be working. <script> $(&ap ...

Retrieve - Obtain the id of the most recently inserted row

I'm struggling with a question similar to this: $query = " INSERT INTO my_table ( column_a, column_b, column_c ) VALUES ( value_1, value_2, value_3 )"; $result = mysqli_query($connection, $query); Does anyone know how I can retrieve the id of the l ...

Enhance PHP code to efficiently insert a large set of 86,000 entries into a MySQL database using XML

Every day, I have to upload a large amount of data from an XML file into my MySQL database using a cron job. However, the process takes around 2 hours to complete. Is there a way to reduce this time? Below is the code I am currently using: I am utilizing ...

symfony submit form without sending request

I'm trying to make a request without using a submit button, only by selecting an option. So far, I've attempted to achieve this using JavaScript but haven't had any success. Here's my form code: $form = $this->createFormBuilder() ...

How can I minimize the number of polymorphic methods in my MVC design?

Currently, I am tackling a challenge in creating an MVC framework using PHP, even though my primary expertise lies in Java. I am on the lookout for a solution that aligns with OOP principles and is easily adaptable to various programming languages. Within ...

What is the best way to simulate an annotated method from AWS in PHPUnit?

Currently, I am in the process of writing a unit test to verify if the method publish() has been called at least once. Here is a snippet from my test class: <?php namespace App\Tests\Unit; use Aws\Sns\SnsClient; use Exception; use ...

The resulting line will consist of the discovered string

Let's say there's an interesting HTML document presented below with associated line numbers: 30 - <div id="myDiv"> 31 - <span class="mySpan">Some Text</span> In this scenario, PHP is being utilized for a specific purpose: $ ...

I keep encountering the same issue every time I try to execute the npm run watch command. Does anyone have any suggestions on how to fix this?

When attempting to execute the command npm run watch, I encountered an error as shown below: ERROR Failed to compile with 1 errors2:50:28 PM This dependency was not found: * vue in ./resources/js/app.js To install it, you can run: npm install --save vue ...

send document through ajax

Having some trouble with this task. Here is what I've managed to put together so far: <input id="newFile" type="file"/> <span style="background-color:orange;" onClick="newImage()">HEYTRY</span> I know it's not much progress. ...

What is the best method to identify the nearest date in an array that can be added to an existing list of

$dates[] = array("date" => "2016-02-18 02:00:00", "duration" => "600"); $dates[] = array("date" => "2016-02-18 02:05:00", "duration" => "300"); $dates[] = array("date" => "2016-02-18 02:10:00", "duration" => "600"); $dates[] = array("date ...

Sophisticated web applications with Ajax functionalities and intricate layouts powered by MVC frameworks

I am looking to integrate an ajax-driven RIA frontend, utilizing JQuery layout plugin (http://layout.jquery-dev.net/demos/complex.html) or ExtJs (http://www.extjs.com/deploy/dev/examples/layout/complex.html), with... a PHP MVC backend, potentially using ...