I'm running a loop as part of an ecommerce system, which loops through each item of a certain type and modifies info prior to inserting in a database. These are magazine subscriptions - here's the content of the loop:
$sub['quantity'] = 1;
if ($sub['country'] == 'US')
{
$region = 'USA';
}
elseif ($sub['country'] == 'CA' || $sub['country'] == 'MX')
{
$region = 'Canada/Mexico';
}
else
{
$region = 'International';
}
$p = new db_Products;
$p->setWhere("type='subscription' AND term=" . $sub['term'] . " AND region='" . $region . "'");
if ($p->getCount() > 0)
{
$p_array = $p->getData();
$sub['productId'] = $p_array[0]['productId'];
}
$sub['subscriptionInfo'] = $sub;
$this->processedItems[] = $sub;
Whenever this runs, I get "undefined variable: sub" at the next-to-last line ($sub['subscriptionInfo'] = $sub😉
Clearly $sub is NOT undefined. In fact even if it was an empty array to start with, I am explicitly giving it "quantity" and "region" elements during the loop.
Also, this error only started about a month ago. It's possible the hosting company made some change in their version of PHP - that's out of my control.
Is it not kosher to copy an array into an element of itself? It's not by reference, so shouldn't be any kind of infinite loop - the element should just be a copy of the array up to the point of the operation. Is it possible there is some PHP update or change that would cause this?