PHP Does try / catch have higher overhead than if?

While working in some legacy code, I came across tons of Try / Catch statements. Try / Catch is not what they learn in my Zend certification classes, and after 10 years I did not work with another PHP developer who used it. Does Try / Catch have any extra overhead compared to applications? What would make it more or less desirable than other options?

+3
source share
5 answers

The whole point try/catchis that it is nonlocal. You can exit several cycles with a stroke, break out of nested function calls, and escape from any place where you end up. ifcannot do this and is not intended. I do not know about overhead, but I strongly and consciously suspect that he has much more than he would if. Ultimately, use the tool to work: they are not interchangeable.

Well, they are, but they should not be changed :)

UPDATE: , try/catch . . . , , ; . , - , ( ).

+3

.

.

Try/Catch . , , Catch.

+9

Try/catch . . . if , , try/catch .

+3

, , try/catch . , . , , , , , . if . , , , try/catch , / ( Throwing exceptions LOT , ).

. . , , . , , . , . - , - , .

+3

, . .

+1

Source: https://habr.com/ru/post/1758431/


All Articles