PHPWarningReference ErrorJune 4, 2026

Reference Error

Notice: Undefined variable: cart in /var/www/html/cart.php on line 67

What This Error Means

This error occurs when a script tries to use a variable that hasn't been declared or initialized yet.

Why It Happens

It usually happens when a developer tries to access a variable before it has been defined, or when a variable is defined in a scope that is not accessible in the current scope.

How to Fix It

  1. 1To fix this error, you need to declare and initialize the variable before using it. In this case, you should add the following line of code before line 67: `$cart = array();` or initialize it with a valid value if it's supposed to be used elsewhere in the script.

Example Code Solution

❌ Before (problematic code)
PHP
if (isset($_GET['item'])) {
    $cart[] = $_GET['item'];
}
✅ After (fixed code)
PHP
$cart = array();
if (isset($_GET['item'])) {
    $cart[] = $_GET['item'];
}

Fix for Notice: Undefined variable: cart in /var/www/html/cart.php on line 67

Related PHP Errors

Related PHP Blog Articles

Have a different error? Get an instant explanation.

Explain Another Error