mercredi 18 juin 2014

PHP foreach stops after first iteration with no apparent reason


Vote count:

0




I'm having lots of trouble with a foreach cycle in PHP.


It's not the usual "break\exit\return\whatever;" issue and I'll explain you the reason:



class Example {
private function generic(/* args */) {
global $db;
$result = false;
/* a series of if and functions, mysql transactions and
"throw new Exception" on rollback */
$notif = new Notification();
$notif->send(/* params */);
/* if commit succeded > $result = true; */
return $result;
}

public function start() {
$list = array("abc" => array("foo" => "bar", "foo2" => "bar"), "def" => array("foo" => "bar", "foo2" => "bar"));
foreach($list as $x => $y) {
$this->generic($x, $y, ....);
}
}
}


The issue seems to be with $notif declaration and\or $notif->send() function.


I tried to try\catch the entire generic() function and also the send() function but no Exception gets thrown up.


The send() function is nothing more than a series of queries and eventually (on user request) it sends an email notification via swiftmailer.


Another detail I can give you is that notification gets successfully sent and everything seems to work just fine on the first iteration, but then the foreach stops.


As I mentioned before: there are no "exit();" or "break;" or "return $x;" at some weird point in the function and so on...


Do you have any idea of what could the issue be, or how can I locate the issue?



asked 3 mins ago






Aucun commentaire:

Enregistrer un commentaire