本文整理汇总了PHP中call_if_exists函数的典型用法代码示例。如果您正苦于以下问题:PHP call_if_exists函数的具体用法?PHP call_if_exists怎么用?PHP call_if_exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了call_if_exists函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: before
function before($route = array())
{
#print_r($route); exit;
#inspect the $route array, looking at various options that may have been passed in
if (@$route['options']['authenticate']) {
authenticate_user() or halt("Access denied");
}
if (@$route['options']['validation_function']) {
call_if_exists($route['options']['validation_function'], params()) or halt("Woops! Params did not pass validation");
}
}
示例2: test_main_call_if_exists
function test_main_call_if_exists()
{
assert_empty(call_if_exists("unknown_function"));
assert_equal(call_if_exists("count", array(1, 2, 3)), 3);
assert_length_of(call_if_exists("array_merge", array(1, 2, 3), array(4, 5, 6)), 6);
class TestCallIfExists
{
public function test($value = 1)
{
return $value * 10;
}
public static function testStatic($value = 1)
{
return $value * 20;
}
}
$obj = new TestCallIfExists();
assert_equal(call_if_exists(array($obj, 'test'), 3), 30);
assert_equal(call_if_exists(array('TestCallIfExists', 'testStatic'), 3), 60);
assert_equal(call_if_exists('TestCallIfExists::testStatic', 3), 60);
}
示例3: error_handler_dispatcher
/**
* Internal error handler dispatcher
* Find and call matching error handler and exit
* If no match found, call default error handler
*
* @access private
* @param int $errno
* @param string $errstr
* @param string $errfile
* @param string $errline
* @return void
*/
function error_handler_dispatcher($errno, $errstr, $errfile, $errline)
{
$back_trace = debug_backtrace();
while ($trace = array_shift($back_trace)) {
if ($trace['function'] == 'halt') {
$errfile = $trace['file'];
$errline = $trace['line'];
break;
}
}
# Notices and warning won't halt execution
if (error_wont_halt_app($errno)) {
error_notice($errno, $errstr, $errfile, $errline);
return;
} else {
# Other errors will stop application
$handlers = error();
$is_http_err = http_response_status_is_valid($errno);
foreach ($handlers as $handler) {
$e = is_array($handler['errno']) ? $handler['errno'] : array($handler['errno']);
while ($ee = array_shift($e)) {
if ($ee == $errno || $ee == E_LIM_PHP || $ee == E_LIM_HTTP && $is_http_err) {
echo call_if_exists($handler['function'], $errno, $errstr, $errfile, $errline);
exit;
}
}
}
echo error_default_handler($errno, $errstr, $errfile, $errline);
stop_and_exit();
}
}
示例4: send_header
/**
* Call before_sending_header() if it exists, then send headers
*
* @param string $header
* @return void
*/
function send_header($header = null, $replace = true, $code = false)
{
if (!headers_sent()) {
call_if_exists('before_sending_header', $header);
header($header, $replace, $code);
}
}
示例5: error_handler_dispatcher
/**
* Internal error handler dispatcher
* Find and call matching error handler and exit
* If no match found, call default error handler
*
* @access private
* @param int $errno
* @param string $errstr
* @param string $errfile
* @param string $errline
* @return void
*/
function error_handler_dispatcher($errno, $errstr, $errfile, $errline)
{
$back_trace = debug_backtrace();
while ($trace = array_shift($back_trace)) {
if ($trace['function'] == 'halt') {
$errfile = $trace['file'];
$errline = $trace['line'];
break;
}
}
$handlers = error();
$is_http_err = http_response_status_is_valid($errno);
foreach ($handlers as $handler) {
$e = is_array($handler['errno']) ? $handler['errno'] : array($handler['errno']);
while ($ee = array_shift($e)) {
if ($ee == $errno || $ee == E_LIM_PHP || $ee == E_LIM_HTTP && $is_http_err) {
echo call_if_exists($handler['function'], $errno, $errstr, $errfile, $errline);
exit;
}
}
}
echo error_default_handler($errno, $errstr, $errfile, $errline);
exit;
}
示例6: test_main_call_if_exists
function test_main_call_if_exists()
{
assert_empty(call_if_exists("unknown_function"));
assert_equal(call_if_exists("count", array(1, 2, 3)), 3);
assert_length_of(call_if_exists("array_merge", array(1, 2, 3), array(4, 5, 6)), 6);
}