I have a function that takes a variable as a reference:
function get_articles($limit = 10, &$more = false){
$results = get_results_from_db($limit);
$more = ($results->found > $limit) ? $results->found : false;
return $results->data;
}
which I use it like:
$articles = get_articles(10, $more_results);
foreach($articles as $article){
// do stuff
}
if($more_results) // we have more than 10 results
But I don’t get a notice telling me that $more_results above is undefined…
Is this normal?
Yes, because
$more_resultswill always be defined at least withfalsevalue (after calling function).Inside function variable will not be defined, but since you doesn’t read content of variable, notice is not generated.