The issue: PHP has exceptions now, cool but dangerous.
- Exceptions are a great tool for handling exceptional states
- Exceptions are often misused and become regulars
- Exceptions may make PHP leaking
<?php
function foo() {
if ($user_input !== "Hello!") {
throw new Exception("User input wrong");
}
}
?>
Only use exceptions, when your application ends up in an exceptional state
<?php
function bar() {
if (connection_timedout()) {
throw new Exception("Connection timeout");
}
}
?>
Exceptions leak a little bit of memory when thrown e.g. out of for loops
<?php
foreach ($i = 1000000; $i > 0; $i--) {
throw new Exceptions("Hehe, I'm leaking");
}
?>
Allocated memory from the for-loop-header is not freeed correctly.