PHP/Language Basics/Assertion — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 07:05, 26 мая 2010
Assertion Options
Constant Name Default Description
ASSERT_ACTIVE true Are assertions enabled?
ASSERT_WARNING true Should assertions cause standard PHP warnings?
ASSERT_BAIL false Should failed assertions cause the script to halt?
ASSERT_QUIET_EVAL false If an error occurs valuating an assertion when passed a string, should it report an error?
ASSERT_CALLBACK NULL The name of the function to call if an assertion fails.
Using the assert() Function
<?php
function add_odd_numbers($x, $y) {
assert("!(($x % 2) && ($y % 2))");
return ($x + $y);
}
$answer_one = add_odd_numbers(3, 5);
$answer_two = add_odd_numbers(2, 4);
echo "3 + 5 = $answer_one\n";
echo "2 + 4 = $answer_two\n";
?>