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
You forget to put
$
before thefp
in if condition.Forgot
$
beforefp
If
$
is appended to a string, it is a variable.If
$
is not appended and we are accessing it, PHP considers it as aCONSTANT
and tries to find out where it is defined.