Ben istisna atma işlevleri kullanarak php benim sınıfların argümanların bazı kontroller yapmak. Ben temel bir çek (===
, in_array
, vb) yapmak işlevlere sahiptir ve yanlış bir istisna. Yani assertNumeric($argument, "\$argument is not numeric.");
yerine yapabilirsiniz
if ( ! is_numeric($argument) ) {
throw new Exception("\$argument is not numeric.");
}
Bazı yazarak kaydeder
Ben php manual page on assert() bu yorumlarından okuyordum
As noted on Wikipedia - "assertions are primarily a development tool, they are often disabled when a program is released to the public." and "Assertions should be used to document logically impossible situations and discover programming errors— if the 'impossible' occurs, then something fundamental is clearly wrong. This is distinct from error handling: most error conditions are possible, although some may be extremely unlikely to occur in practice. Using assertions as a general-purpose error handling mechanism is usually unwise: assertions do not allow for graceful recovery from errors, and an assertion failure will often halt the program's execution abruptly. Assertions also do not display a user-friendly error message."
This means that the advice given by "gk at proliberty dot com" to force assertions to be enabled, even when they have been disabled manually, goes against best practices of only using them as a development tool
Yani, 'yanlış yapıyorsun' ben? / Bunu yapmanın daha iyi bir yolu başka ne vardır?