I am experiencing "Undefined variable" error when returning an array from a class, but I do not understand why this would happen.
If I print_r($order_ids)
from within the class, there is no issue. The issue only occurs when I try to print_r($order_ids)
from outside the class.
CLASS FUNCTIONS FILE
function getOrderIds($start_order, $end_order) {
$conn = new Database();
$sql = "SELECT order_id FROM oc_order WHERE order_status_id = '17' AND order_id BETWEEN '$start_order' AND '$end_order'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$order_ids[] = $row['order_id'];
}
}
return($order_ids);
}
CALL
$order = new Order();
$order->getOrderIds($start_order, $end_order);
print_r($order_ids);
RESULT
Notice: Undefined variable: order_ids