skip to Main Content

I have problem witth this warning:

Warning: Use of undefined constant fp - assumed 'fp'

My code is:

<?php
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
@ $fp = fopen("$DOCUMENT_ROOT/orders/orders.txt", 'rb');
if (!fp) {
    echo "<p>No orders pending. Please try later.</p>";
    exit;
}
while (!feof($fp)) {
    $order = fgets ($fp, 999);
    echo $order."<br />";
}
?>

I have PHP Version 7.2.34.
Please help me to solve the warning.

2

Answers


  1. You forget to put $ before the fp in if condition.

    if (!$fp) {
        echo "<p>No orders pending. Please try later.</p>";
        exit;
    }
    
    Login or Signup to reply.
  2. Forgot $ before fp

    If $ is appended to a string, it is a variable.

    If $ is not appended and we are accessing it, PHP considers it as a CONSTANT and tries to find out where it is defined.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search