Your code is evaluated as follows:
while (!($apns = ($this->getApns($streamContext) && ($z < 11))))
therefore you see an infinite loop (as soon as $z >= 11 , $apns is false, so the condition is always true). The reason for this priority is that special rules only apply to ! to the left of an assignment with a lower priority than = ). It does not affect the logical operator on the right, which behaves as in any normal language.
Your style is bad. Try this, which is much readable and differs only in the final value of $z (and if it is important, you can configure the break statement.
for( $z = 1; $z < 11; ++ $z ) { // note extra brackets to make it clear that we intend to do assignment not comparison if( ($apns = $this->getApns($streamContext)) ) { break; } myerror_log("unable to conncect to apple. sleep for 2 seconds and try again"); sleep(2); }
source share