本文整理汇总了PHP中debug::caller_backtrace方法的典型用法代码示例。如果您正苦于以下问题:PHP debug::caller_backtrace方法的具体用法?PHP debug::caller_backtrace怎么用?PHP debug::caller_backtrace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类debug
的用法示例。
在下文中一共展示了debug::caller_backtrace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: assert
/**
* Checks $condition, if false, throw the static exception class
*
* @param mixed $condition
* @param string $message the error message
* @param mixed $data extra data of the error
* @param int $error_number the error code
*
* @since ADD MVC 0.0
* @version 0.1
*/
static function assert($condition, $message = null, $data = NULL, $error_number = NULL)
{
if (!$condition) {
if (!$message) {
$caller_backtrace = debug::caller_backtrace();
$file_lines = file($caller_backtrace['file']);
$file_line_content = $file_lines[$caller_backtrace['line'] - 1];
$tokens = token_get_all("<?php {$file_line_content} ?>");
$assert_arguments = array();
$assert_argument_string = "";
$on_argument = false;
for ($token_x = 0; isset($tokens[$token_x]); ++$token_x) {
$token = $tokens[$token_x];
if ($token === array(307, get_called_class(), 1) && isset($tokens[$token_x + 1])) {
$pn_token = $tokens[++$token_x];
# Paamayim Nekudotayim
if ($pn_token === array(376, "::", 1) && isset($tokens[$token_x + 2])) {
$assert_token = $tokens[++$token_x];
if ($assert_token === array(307, __FUNCTION__, 1)) {
$parenthesis_count = 1;
$on_argument = true;
++$token_x;
continue;
}
}
}
if ($on_argument) {
if ($token === '(') {
++$parenthesis_count;
}
if ($token === ')') {
--$parenthesis_count;
}
if ($parenthesis_count <= 0) {
break;
}
$assert_argument_string .= is_array($token) ? $token[1] : $token;
}
}
if (!$assert_argument_string) {
$assert_argument_string = preg_replace('/^\\s*\\$?\\w+\\:\\:assert\\((.+)(\\,.+)?\\)\\;/', '$1', $file_line_content);
}
if (preg_match('/(?P<function_name>\\w+)\\((?P<arguments>.*?)\\)/', $assert_argument_string, $assert_condition_parts)) {
$function = $assert_condition_parts['function_name'];
$arguments = $assert_condition_parts['arguments'];
switch ($function) {
case 'is_int':
$message = "{$arguments} is not integer";
break;
case 'is_array':
$message = "{$arguments} is not array";
break;
case 'is_bool':
$message = "{$arguments} is not boolean";
break;
case 'is_callable':
$message = "{$arguments} is not callable";
break;
case 'is_double':
$message = "{$arguments} is not double";
break;
case 'is_float':
$message = "{$arguments} is not float";
break;
case 'is_null':
$message = "{$arguments} is not null";
break;
case 'is_numeric':
$message = "{$arguments} is not numeric";
break;
case 'is_object':
$message = "{$arguments} is not object";
break;
case 'is_resource':
$message = "{$arguments} is not resource";
break;
case 'is_scalar':
$message = "{$arguments} is not scalar";
break;
case 'is_string':
$message = "{$arguments} is not string";
break;
case 'isset':
$message = "{$arguments} is not set";
break;
case 'empty':
$message = "{$arguments} is not empty";
break;
case 'ctype_digit':
//.........这里部分代码省略.........
示例2: assert
/**
* Checks $condition, if false, throw the exception class
*
* @param mixed $condition
* @param string $message the error message
* @param int $error_number the error code
* @param mixed $data extra data of the error
*
* @since ADD MVC 0.0
* @version 0.1
*/
static function assert($condition, $message = null, $data = NULL, $error_number = NULL)
{
if (!$condition) {
if (!$message) {
$caller_backtrace = debug::caller_backtrace();
$file_lines = file($caller_backtrace['file']);
$file_line_content = $file_lines[$caller_backtrace['line'] - 1];
$assert_condition = preg_replace('/^\\s*\\w+\\:\\:assert\\((.+)(\\,.+)?\\)\\;/', '$1', $file_line_content);
if (preg_match('/(?P<function_name>\\w+)\\((?P<arguments>.*?)\\)/', $assert_condition, $assert_condition_parts)) {
$function = $assert_condition_parts['function_name'];
$arguments = $assert_condition_parts['arguments'];
switch ($function) {
case 'is_int':
$message = "{$arguments} is not integer";
break;
case 'is_array':
$message = "{$arguments} is not array";
break;
case 'is_bool':
$message = "{$arguments} is not boolean";
break;
case 'is_callable':
$message = "{$arguments} is not callable";
break;
case 'is_double':
$message = "{$arguments} is not double";
break;
case 'is_float':
$message = "{$arguments} is not float";
break;
case 'is_null':
$message = "{$arguments} is not null";
break;
case 'is_numeric':
$message = "{$arguments} is not numeric";
break;
case 'is_object':
$message = "{$arguments} is not object";
break;
case 'is_resource':
$message = "{$arguments} is not resource";
break;
case 'is_scalar':
$message = "{$arguments} is not scalar";
break;
case 'is_string':
$message = "{$arguments} is not string";
break;
case 'isset':
$message = "{$arguments} is not set";
break;
case 'empty':
$message = "{$arguments} is not empty";
break;
case 'ctype_digit':
$message = "{$arguments} is not numeric";
break;
case 'is_float':
$message = "{$arguments} is not float";
break;
case 'filter_var':
$message = "{$arguments} is not accepted";
break;
case 'filter_has_var':
$message = "{$arguments} does not exist";
break;
case 'filter_input_array':
$message = "{$arguments} is not accepted";
break;
case 'filter_has_var':
$message = "{$arguments} does not exist";
break;
default:
$message = "Failed to validate {$function} ({$arguments}) ";
}
} else {
$message = "Failed to validate condition " . $assert_condition;
}
}
$e = new static($message, $error_number);
$e->data = $data;
throw $e;
}
}