PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - Zend - zend_exceptions.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 341 411 83.0 %
Date: 2015-08-27 Functions: 31 34 91.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2014 Zend Technologies Ltd. (http://www.zend.com) |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 2.00 of the Zend license,     |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.zend.com/license/2_00.txt.                                |
      11             :    | If you did not receive a copy of the Zend license and are unable to  |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@zend.com so we can mail you a copy immediately.              |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andi Gutmans <andi@zend.com>                                |
      16             :    |          Marcus Boerger <helly@php.net>                              |
      17             :    |          Sterling Hughes <sterling@php.net>                          |
      18             :    |          Zeev Suraski <zeev@zend.com>                                |
      19             :    +----------------------------------------------------------------------+
      20             : */
      21             : 
      22             : /* $Id$ */
      23             : 
      24             : #include "zend.h"
      25             : #include "zend_API.h"
      26             : #include "zend_builtin_functions.h"
      27             : #include "zend_interfaces.h"
      28             : #include "zend_exceptions.h"
      29             : #include "zend_vm.h"
      30             : #include "zend_dtrace.h"
      31             : 
      32             : static zend_class_entry *default_exception_ce;
      33             : static zend_class_entry *error_exception_ce;
      34             : static zend_object_handlers default_exception_handlers;
      35             : ZEND_API void (*zend_throw_exception_hook)(zval *ex TSRMLS_DC);
      36             : 
      37        1207 : void zend_exception_set_previous(zval *exception, zval *add_previous TSRMLS_DC)
      38             : {
      39             :         zval *previous;
      40             : 
      41        1207 :         if (exception == add_previous || !add_previous || !exception) {
      42        1201 :                 return;
      43             :         }
      44           6 :         if (Z_TYPE_P(add_previous) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(add_previous), default_exception_ce TSRMLS_CC)) {
      45           0 :                 zend_error(E_ERROR, "Cannot set non exception as previous exception");
      46           0 :                 return;
      47             :         }
      48          12 :         while (exception && exception != add_previous && Z_OBJ_HANDLE_P(exception) != Z_OBJ_HANDLE_P(add_previous)) {
      49           6 :                 previous = zend_read_property(default_exception_ce, exception, "previous", sizeof("previous")-1, 1 TSRMLS_CC);
      50           6 :                 if (Z_TYPE_P(previous) == IS_NULL) {
      51           6 :                         zend_update_property(default_exception_ce, exception, "previous", sizeof("previous")-1, add_previous TSRMLS_CC);
      52             :                         Z_DELREF_P(add_previous);
      53           6 :                         return;
      54             :                 }
      55           0 :                 exception = previous;
      56             :         }
      57             : }
      58             : 
      59         663 : void zend_exception_save(TSRMLS_D) /* {{{ */
      60             : {
      61         663 :         if (EG(prev_exception)) {
      62           4 :                 zend_exception_set_previous(EG(exception), EG(prev_exception) TSRMLS_CC);
      63             :         }
      64         663 :         if (EG(exception)) {
      65          15 :                 EG(prev_exception) = EG(exception);
      66             :         }
      67         663 :         EG(exception) = NULL;
      68         663 : }
      69             : /* }}} */
      70             : 
      71       20363 : void zend_exception_restore(TSRMLS_D) /* {{{ */
      72             : {
      73       20363 :         if (EG(prev_exception)) {
      74          15 :                 if (EG(exception)) {
      75           3 :                         zend_exception_set_previous(EG(exception), EG(prev_exception) TSRMLS_CC);
      76             :                 } else {
      77          12 :                         EG(exception) = EG(prev_exception);
      78             :                 }
      79          15 :                 EG(prev_exception) = NULL;
      80             :         }
      81       20363 : }
      82             : /* }}} */
      83             : 
      84        2620 : void zend_throw_exception_internal(zval *exception TSRMLS_DC) /* {{{ */
      85             : {
      86             : #ifdef HAVE_DTRACE
      87             :         if (DTRACE_EXCEPTION_THROWN_ENABLED()) {
      88             :                 const char *classname;
      89             :                 zend_uint name_len;
      90             : 
      91             :                 if (exception != NULL) {
      92             :                         zend_get_object_classname(exception, &classname, &name_len TSRMLS_CC);
      93             :                         DTRACE_EXCEPTION_THROWN((char *)classname);
      94             :                 } else {
      95             :                         DTRACE_EXCEPTION_THROWN(NULL);
      96             :                 }
      97             :         }
      98             : #endif /* HAVE_DTRACE */
      99             : 
     100        2620 :         if (exception != NULL) {
     101        1197 :                 zval *previous = EG(exception);
     102        1197 :                 zend_exception_set_previous(exception, EG(exception) TSRMLS_CC);
     103        1197 :                 EG(exception) = exception;
     104        1197 :                 if (previous) {
     105           0 :                         return;
     106             :                 }
     107             :         }
     108        2620 :         if (!EG(current_execute_data)) {
     109           3 :                 if(EG(exception)) {
     110           3 :                         zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
     111             :                 }
     112           0 :                 zend_error(E_ERROR, "Exception thrown without a stack frame");
     113             :         }
     114             : 
     115        2617 :         if (zend_throw_exception_hook) {
     116           0 :                 zend_throw_exception_hook(exception TSRMLS_CC);
     117             :         }
     118             : 
     119        5151 :         if (EG(current_execute_data)->opline == NULL ||
     120        2534 :             (EG(current_execute_data)->opline+1)->opcode == ZEND_HANDLE_EXCEPTION) {
     121             :                 /* no need to rethrow the exception */
     122        1074 :                 return;
     123             :         }
     124        1543 :         EG(opline_before_exception) = EG(current_execute_data)->opline;
     125        1543 :         EG(current_execute_data)->opline = EG(exception_op);
     126             : }
     127             : /* }}} */
     128             : 
     129         101 : ZEND_API void zend_clear_exception(TSRMLS_D) /* {{{ */
     130             : {
     131         101 :         if (EG(prev_exception)) {
     132           0 :                 zval_ptr_dtor(&EG(prev_exception));
     133           0 :                 EG(prev_exception) = NULL;
     134             :         }
     135         101 :         if (!EG(exception)) {
     136          91 :                 return;
     137             :         }
     138          10 :         zval_ptr_dtor(&EG(exception));
     139          10 :         EG(exception) = NULL;
     140          10 :         EG(current_execute_data)->opline = EG(opline_before_exception);
     141             : #if ZEND_DEBUG
     142             :         EG(opline_before_exception) = NULL;
     143             : #endif
     144             : }
     145             : /* }}} */
     146             : 
     147        1617 : static zend_object_value zend_default_exception_new_ex(zend_class_entry *class_type, int skip_top_traces TSRMLS_DC) /* {{{ */
     148             : {
     149             :         zval obj;
     150             :         zend_object *object;
     151             :         zval *trace;
     152             : 
     153        1617 :         Z_OBJVAL(obj) = zend_objects_new(&object, class_type TSRMLS_CC);
     154        1617 :         Z_OBJ_HT(obj) = &default_exception_handlers;
     155             : 
     156        1617 :         object_properties_init(object, class_type);
     157             : 
     158        1617 :         ALLOC_ZVAL(trace);
     159             :         Z_UNSET_ISREF_P(trace);
     160             :         Z_SET_REFCOUNT_P(trace, 0);
     161        1617 :         zend_fetch_debug_backtrace(trace, skip_top_traces, 0, 0 TSRMLS_CC);
     162             : 
     163        1617 :         zend_update_property_string(default_exception_ce, &obj, "file", sizeof("file")-1, zend_get_executed_filename(TSRMLS_C) TSRMLS_CC);
     164        1617 :         zend_update_property_long(default_exception_ce, &obj, "line", sizeof("line")-1, zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC);
     165        1617 :         zend_update_property(default_exception_ce, &obj, "trace", sizeof("trace")-1, trace TSRMLS_CC);
     166             : 
     167        1617 :         return Z_OBJVAL(obj);
     168             : }
     169             : /* }}} */
     170             : 
     171        1615 : static zend_object_value zend_default_exception_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
     172             : {
     173        1615 :         return zend_default_exception_new_ex(class_type, 0 TSRMLS_CC);
     174             : }
     175             : /* }}} */
     176             : 
     177           2 : static zend_object_value zend_error_exception_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
     178             : {
     179           2 :         return zend_default_exception_new_ex(class_type, 2 TSRMLS_CC);
     180             : }
     181             : /* }}} */
     182             : 
     183             : /* {{{ proto Exception Exception::__clone()
     184             :    Clone the exception object */
     185           0 : ZEND_METHOD(exception, __clone)
     186             : {
     187             :         /* Should never be executable */
     188           0 :         zend_throw_exception(NULL, "Cannot clone object using __clone()", 0 TSRMLS_CC);
     189           0 : }
     190             : /* }}} */
     191             : 
     192             : /* {{{ proto Exception::__construct(string message, int code [, Exception previous])
     193             :    Exception constructor */
     194         265 : ZEND_METHOD(exception, __construct)
     195             : {
     196         265 :         char  *message = NULL;
     197         265 :         long   code = 0;
     198         265 :         zval  *object, *previous = NULL;
     199         265 :         int    argc = ZEND_NUM_ARGS(), message_len;
     200             : 
     201         265 :         if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, "|slO!", &message, &message_len, &code, &previous, default_exception_ce) == FAILURE) {
     202           0 :                 zend_error(E_ERROR, "Wrong parameters for Exception([string $exception [, long $code [, Exception $previous = NULL]]])");
     203             :         }
     204             : 
     205         265 :         object = getThis();
     206             : 
     207         265 :         if (message) {
     208         182 :                 zend_update_property_stringl(default_exception_ce, object, "message", sizeof("message")-1, message, message_len TSRMLS_CC);
     209             :         }
     210             : 
     211         265 :         if (code) {
     212          12 :                 zend_update_property_long(default_exception_ce, object, "code", sizeof("code")-1, code TSRMLS_CC);
     213             :         }
     214             : 
     215         265 :         if (previous) {
     216           3 :                 zend_update_property(default_exception_ce, object, "previous", sizeof("previous")-1, previous TSRMLS_CC);
     217             :         }
     218         265 : }
     219             : /* }}} */
     220             : 
     221             : /* {{{ proto Exception::__wakeup()
     222             :    Exception unserialize checks */
     223             : #define CHECK_EXC_TYPE(name, type) \
     224             :         value = zend_read_property(default_exception_ce, object, name, sizeof(name)-1, 0 TSRMLS_CC); \
     225             :         if(value && Z_TYPE_P(value) != type) { \
     226             :                 zval *tmp; \
     227             :                 MAKE_STD_ZVAL(tmp); \
     228             :                 ZVAL_STRINGL(tmp, name, sizeof(name)-1, 1); \
     229             :                 Z_OBJ_HANDLER_P(object, unset_property)(object, tmp, 0 TSRMLS_CC); \
     230             :                 zval_ptr_dtor(&tmp); \
     231             :         }
     232             : 
     233           3 : ZEND_METHOD(exception, __wakeup)
     234             : {
     235             :         zval *value;
     236           3 :         zval *object = getThis();
     237           3 :         HashTable *intern_ht = zend_std_get_properties(getThis() TSRMLS_CC);
     238           3 :         CHECK_EXC_TYPE("message", IS_STRING);
     239           3 :         CHECK_EXC_TYPE("string", IS_STRING);
     240           3 :         CHECK_EXC_TYPE("code", IS_LONG);
     241           3 :         CHECK_EXC_TYPE("file", IS_STRING);
     242           3 :         CHECK_EXC_TYPE("line", IS_LONG);
     243           3 :         CHECK_EXC_TYPE("trace", IS_ARRAY);
     244           3 :         CHECK_EXC_TYPE("previous", IS_OBJECT);
     245           3 : }
     246             : /* }}} */
     247             : 
     248             : /* {{{ proto ErrorException::__construct(string message, int code, int severity [, string filename [, int lineno [, Exception previous]]])
     249             :    ErrorException constructor */
     250           2 : ZEND_METHOD(error_exception, __construct)
     251             : {
     252           2 :         char  *message = NULL, *filename = NULL;
     253           2 :         long   code = 0, severity = E_ERROR, lineno;
     254           2 :         zval  *object, *previous = NULL;
     255           2 :         int    argc = ZEND_NUM_ARGS(), message_len, filename_len;
     256             : 
     257           2 :         if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC, "|sllslO!", &message, &message_len, &code, &severity, &filename, &filename_len, &lineno, &previous, default_exception_ce) == FAILURE) {
     258           0 :                 zend_error(E_ERROR, "Wrong parameters for ErrorException([string $exception [, long $code, [ long $severity, [ string $filename, [ long $lineno  [, Exception $previous = NULL]]]]]])");
     259             :         }
     260             : 
     261           2 :         object = getThis();
     262             : 
     263           2 :         if (message) {
     264           2 :                 zend_update_property_string(default_exception_ce, object, "message", sizeof("message")-1, message TSRMLS_CC);
     265             :         }
     266             : 
     267           2 :         if (code) {
     268           1 :                 zend_update_property_long(default_exception_ce, object, "code", sizeof("code")-1, code TSRMLS_CC);
     269             :         }
     270             : 
     271           2 :         if (previous) {
     272           0 :                 zend_update_property(default_exception_ce, object, "previous", sizeof("previous")-1, previous TSRMLS_CC);
     273             :         }
     274             : 
     275           2 :         zend_update_property_long(default_exception_ce, object, "severity", sizeof("severity")-1, severity TSRMLS_CC);
     276             : 
     277           2 :         if (argc >= 4) {
     278           2 :             zend_update_property_string(default_exception_ce, object, "file", sizeof("file")-1, filename TSRMLS_CC);
     279           2 :         if (argc < 5) {
     280           0 :             lineno = 0; /* invalidate lineno */
     281             :         }
     282           2 :         zend_update_property_long(default_exception_ce, object, "line", sizeof("line")-1, lineno TSRMLS_CC);
     283             :         }
     284           2 : }
     285             : /* }}} */
     286             : 
     287             : #define DEFAULT_0_PARAMS \
     288             :         if (zend_parse_parameters_none() == FAILURE) { \
     289             :                 return; \
     290             :         }
     291             : 
     292        1299 : static void _default_exception_get_entry(zval *object, char *name, int name_len, zval *return_value TSRMLS_DC) /* {{{ */
     293             : {
     294             :         zval *value;
     295             : 
     296        1299 :         value = zend_read_property(default_exception_ce, object, name, name_len, 0 TSRMLS_CC);
     297             : 
     298        1299 :         *return_value = *value;
     299             :         zval_copy_ctor(return_value);
     300        1299 :         INIT_PZVAL(return_value);
     301        1299 : }
     302             : /* }}} */
     303             : 
     304             : /* {{{ proto string Exception::getFile()
     305             :    Get the file in which the exception occurred */
     306           6 : ZEND_METHOD(exception, getFile)
     307             : {
     308           6 :         DEFAULT_0_PARAMS;
     309             : 
     310           5 :         _default_exception_get_entry(getThis(), "file", sizeof("file")-1, return_value TSRMLS_CC);
     311             : }
     312             : /* }}} */
     313             : 
     314             : /* {{{ proto int Exception::getLine()
     315             :    Get the line in which the exception occurred */
     316          13 : ZEND_METHOD(exception, getLine)
     317             : {
     318          13 :         DEFAULT_0_PARAMS;
     319             : 
     320          12 :         _default_exception_get_entry(getThis(), "line", sizeof("line")-1, return_value TSRMLS_CC);
     321             : }
     322             : /* }}} */
     323             : 
     324             : /* {{{ proto string Exception::getMessage()
     325             :    Get the exception message */
     326         889 : ZEND_METHOD(exception, getMessage)
     327             : {
     328         889 :         DEFAULT_0_PARAMS;
     329             : 
     330         888 :         _default_exception_get_entry(getThis(), "message", sizeof("message")-1, return_value TSRMLS_CC);
     331             : }
     332             : /* }}} */
     333             : 
     334             : /* {{{ proto int Exception::getCode()
     335             :    Get the exception code */
     336          18 : ZEND_METHOD(exception, getCode)
     337             : {
     338          18 :         DEFAULT_0_PARAMS;
     339             : 
     340          17 :         _default_exception_get_entry(getThis(), "code", sizeof("code")-1, return_value TSRMLS_CC);
     341             : }
     342             : /* }}} */
     343             : 
     344             : /* {{{ proto array Exception::getTrace()
     345             :    Get the stack trace for the location in which the exception occurred */
     346           6 : ZEND_METHOD(exception, getTrace)
     347             : {
     348           6 :         DEFAULT_0_PARAMS;
     349             : 
     350           5 :         _default_exception_get_entry(getThis(), "trace", sizeof("trace")-1, return_value TSRMLS_CC);
     351             : }
     352             : /* }}} */
     353             : 
     354             : /* {{{ proto int ErrorException::getSeverity()
     355             :    Get the exception severity */
     356           0 : ZEND_METHOD(error_exception, getSeverity)
     357             : {
     358           0 :         DEFAULT_0_PARAMS;
     359             : 
     360           0 :         _default_exception_get_entry(getThis(), "severity", sizeof("severity")-1, return_value TSRMLS_CC);
     361             : }
     362             : /* }}} */
     363             : 
     364             : /* {{{ gettraceasstring() macros */
     365             : #define TRACE_APPEND_CHR(chr)                                            \
     366             :         *str = (char*)erealloc(*str, *len + 1 + 1);                          \
     367             :         (*str)[(*len)++] = chr
     368             : 
     369             : #define TRACE_APPEND_STRL(val, vallen)                                   \
     370             :         {                                                                    \
     371             :                 int l = vallen;                                                  \
     372             :                 *str = (char*)erealloc(*str, *len + l + 1);                      \
     373             :                 memcpy((*str) + *len, val, l);                                   \
     374             :                 *len += l;                                                       \
     375             :         }
     376             : 
     377             : #define TRACE_APPEND_STR(val)                                            \
     378             :         TRACE_APPEND_STRL(val, sizeof(val)-1)
     379             : 
     380             : #define TRACE_APPEND_KEY(key)                                                   \
     381             :         if (zend_hash_find(ht, key, sizeof(key), (void**)&tmp) == SUCCESS) {    \
     382             :                 if (Z_TYPE_PP(tmp) != IS_STRING) {                              \
     383             :                         zend_error(E_WARNING, "Value for %s is no string", key); \
     384             :                         TRACE_APPEND_STR("[unknown]");                          \
     385             :                 } else {                                                        \
     386             :                         TRACE_APPEND_STRL(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));  \
     387             :                 }                                                               \
     388             :         }
     389             : 
     390             : 
     391             : #define TRACE_ARG_APPEND(vallen)                                                                \
     392             :         *str = (char*)erealloc(*str, *len + 1 + vallen);                                        \
     393             :         memmove((*str) + *len - l_added + 1 + vallen, (*str) + *len - l_added + 1, l_added);
     394             : 
     395             : /* }}} */
     396             : 
     397         212 : static int _build_trace_args(zval **arg TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
     398             : {
     399             :         char **str;
     400             :         int *len;
     401             : 
     402         212 :         str = va_arg(args, char**);
     403         212 :         len = va_arg(args, int*);
     404             : 
     405             :         /* the trivial way would be to do:
     406             :          * convert_to_string_ex(arg);
     407             :          * append it and kill the now tmp arg.
     408             :          * but that could cause some E_NOTICE and also damn long lines.
     409             :          */
     410             : 
     411         212 :         switch (Z_TYPE_PP(arg)) {
     412             :                 case IS_NULL:
     413           0 :                         TRACE_APPEND_STR("NULL, ");
     414           0 :                         break;
     415             :                 case IS_STRING: {
     416             :                         int l_added;
     417         117 :                         TRACE_APPEND_CHR('\'');
     418         117 :                         if (Z_STRLEN_PP(arg) > 15) {
     419          44 :                                 TRACE_APPEND_STRL(Z_STRVAL_PP(arg), 15);
     420          44 :                                 TRACE_APPEND_STR("...', ");
     421          44 :                                 l_added = 15 + 6 + 1; /* +1 because of while (--l_added) */
     422             :                         } else {
     423          73 :                                 l_added = Z_STRLEN_PP(arg);
     424          73 :                                 TRACE_APPEND_STRL(Z_STRVAL_PP(arg), l_added);
     425          73 :                                 TRACE_APPEND_STR("', ");
     426          73 :                                 l_added += 3 + 1;
     427             :                         }
     428        1767 :                         while (--l_added) {
     429        1533 :                                 unsigned char chr = (*str)[*len - l_added];
     430        1533 :                                 if (chr < 32 || chr == '\\' || chr > 126) {
     431           5 :                                         (*str)[*len - l_added] = '\\';
     432             : 
     433           5 :                                         switch (chr) {
     434             :                                                 case '\n':
     435           0 :                                                         TRACE_ARG_APPEND(1);
     436           0 :                                                         (*str)[++(*len) - l_added] = 'n';
     437           0 :                                                         break;
     438             :                                                 case '\r':
     439           0 :                                                         TRACE_ARG_APPEND(1);
     440           0 :                                                         (*str)[++(*len) - l_added] = 'r';
     441           0 :                                                         break;
     442             :                                                 case '\t':
     443           0 :                                                         TRACE_ARG_APPEND(1);
     444           0 :                                                         (*str)[++(*len) - l_added] = 't';
     445           0 :                                                         break;
     446             :                                                 case '\f':
     447           0 :                                                         TRACE_ARG_APPEND(1);
     448           0 :                                                         (*str)[++(*len) - l_added] = 'f';
     449           0 :                                                         break;
     450             :                                                 case '\v':
     451           0 :                                                         TRACE_ARG_APPEND(1);
     452           0 :                                                         (*str)[++(*len) - l_added] = 'v';
     453           0 :                                                         break;
     454             : #ifndef PHP_WIN32
     455             :                                                 case '\e':
     456             : #else
     457             :                                                 case VK_ESCAPE:
     458             : #endif
     459           0 :                                                         TRACE_ARG_APPEND(1);
     460           0 :                                                         (*str)[++(*len) - l_added] = 'e';
     461           0 :                                                         break;
     462             :                                                 case '\\':
     463           0 :                                                         TRACE_ARG_APPEND(1);
     464           0 :                                                         (*str)[++(*len) - l_added] = '\\';
     465           0 :                                                         break;
     466             :                                                 default:
     467           5 :                                                         TRACE_ARG_APPEND(3);
     468           5 :                                                         (*str)[*len - l_added + 1] = 'x';
     469           5 :                                                         if ((chr >> 4) < 10) {
     470           5 :                                                                 (*str)[*len - l_added + 2] = (chr >> 4) + '0';
     471             :                                                         } else {
     472           0 :                                                                 (*str)[*len - l_added + 2] = (chr >> 4) + 'A' - 10;
     473             :                                                         }
     474           5 :                                                         if (chr % 16 < 10) {
     475           5 :                                                                 (*str)[*len - l_added + 3] = chr % 16 + '0';
     476             :                                                         } else {
     477           0 :                                                                 (*str)[*len - l_added + 3] = chr % 16 + 'A' - 10;
     478             :                                                         }
     479           5 :                                                         *len += 3;
     480             :                                         }
     481             :                                 }
     482             :                         }
     483         117 :                         break;
     484             :                 }
     485             :                 case IS_BOOL:
     486           1 :                         if (Z_LVAL_PP(arg)) {
     487           1 :                                 TRACE_APPEND_STR("true, ");
     488             :                         } else {
     489           0 :                                 TRACE_APPEND_STR("false, ");
     490             :                         }
     491           1 :                         break;
     492             :                 case IS_RESOURCE:
     493           1 :                         TRACE_APPEND_STR("Resource id #");
     494             :                         /* break; */
     495             :                 case IS_LONG: {
     496          32 :                         long lval = Z_LVAL_PP(arg);
     497             :                         char s_tmp[MAX_LENGTH_OF_LONG + 1];
     498          32 :                         int l_tmp = zend_sprintf(s_tmp, "%ld", lval);  /* SAFE */
     499          32 :                         TRACE_APPEND_STRL(s_tmp, l_tmp);
     500          32 :                         TRACE_APPEND_STR(", ");
     501          32 :                         break;
     502             :                 }
     503             :                 case IS_DOUBLE: {
     504           0 :                         double dval = Z_DVAL_PP(arg);
     505             :                         char *s_tmp;
     506             :                         int l_tmp;
     507             : 
     508           0 :                         s_tmp = emalloc(MAX_LENGTH_OF_DOUBLE + EG(precision) + 1);
     509           0 :                         l_tmp = zend_sprintf(s_tmp, "%.*G", (int) EG(precision), dval);  /* SAFE */
     510           0 :                         TRACE_APPEND_STRL(s_tmp, l_tmp);
     511             :                         /* %G already handles removing trailing zeros from the fractional part, yay */
     512           0 :                         efree(s_tmp);
     513           0 :                         TRACE_APPEND_STR(", ");
     514           0 :                         break;
     515             :                 }
     516             :                 case IS_ARRAY:
     517          42 :                         TRACE_APPEND_STR("Array, ");
     518          42 :                         break;
     519             :                 case IS_OBJECT: {
     520             :                         const char *class_name;
     521             :                         zend_uint class_name_len;
     522             :                         int dup;
     523             : 
     524          20 :                         TRACE_APPEND_STR("Object(");
     525             : 
     526          20 :                         dup = zend_get_object_classname(*arg, &class_name, &class_name_len TSRMLS_CC);
     527             : 
     528          20 :                         TRACE_APPEND_STRL(class_name, class_name_len);
     529          20 :                         if(!dup) {
     530          20 :                                 efree((char*)class_name);
     531             :                         }
     532             : 
     533          20 :                         TRACE_APPEND_STR("), ");
     534             :                         break;
     535             :                 }
     536             :                 default:
     537             :                         break;
     538             :         }
     539         212 :         return ZEND_HASH_APPLY_KEEP;
     540             : }
     541             : /* }}} */
     542             : 
     543         165 : static int _build_trace_string(zval **frame TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
     544             : {
     545             :         char *s_tmp, **str;
     546             :         int *len, *num;
     547             :         long line;
     548         165 :         HashTable *ht = Z_ARRVAL_PP(frame);
     549             :         zval **file, **tmp;
     550             : 
     551         165 :         if (Z_TYPE_PP(frame) != IS_ARRAY) {
     552           1 :                 zend_error(E_WARNING, "Expected array for frame %lu", hash_key->h);
     553           1 :                 return ZEND_HASH_APPLY_KEEP;
     554             :         }
     555             : 
     556         164 :         str = va_arg(args, char**);
     557         164 :         len = va_arg(args, int*);
     558         164 :         num = va_arg(args, int*);
     559             : 
     560         164 :         s_tmp = emalloc(1 + MAX_LENGTH_OF_LONG + 1 + 1);
     561         164 :         sprintf(s_tmp, "#%d ", (*num)++);
     562         164 :         TRACE_APPEND_STRL(s_tmp, strlen(s_tmp));
     563         164 :         efree(s_tmp);
     564         164 :         if (zend_hash_find(ht, "file", sizeof("file"), (void**)&file) == SUCCESS) {
     565         127 :                 if (Z_TYPE_PP(file) != IS_STRING) {
     566           1 :                         zend_error(E_WARNING, "Function name is no string");
     567           1 :                         TRACE_APPEND_STR("[unknown function]");
     568             :                 } else{
     569         126 :                         if (zend_hash_find(ht, "line", sizeof("line"), (void**)&tmp) == SUCCESS) {
     570         126 :                                 if (Z_TYPE_PP(tmp) == IS_LONG) {
     571         126 :                                         line = Z_LVAL_PP(tmp);
     572             :                                 } else {
     573           0 :                                         zend_error(E_WARNING, "Line is no long");
     574           0 :                                         line = 0;
     575             :                                 }
     576             :                         } else {
     577           0 :                                 line = 0;
     578             :                         }
     579         126 :                         s_tmp = emalloc(Z_STRLEN_PP(file) + MAX_LENGTH_OF_LONG + 4 + 1);
     580         126 :                         sprintf(s_tmp, "%s(%ld): ", Z_STRVAL_PP(file), line);
     581         126 :                         TRACE_APPEND_STRL(s_tmp, strlen(s_tmp));
     582         126 :                         efree(s_tmp);
     583             :                 }
     584             :         } else {
     585          37 :                 TRACE_APPEND_STR("[internal function]: ");
     586             :         }
     587         164 :         TRACE_APPEND_KEY("class");
     588         164 :         TRACE_APPEND_KEY("type");
     589         164 :         TRACE_APPEND_KEY("function");
     590         164 :         TRACE_APPEND_CHR('(');
     591         164 :         if (zend_hash_find(ht, "args", sizeof("args"), (void**)&tmp) == SUCCESS) {
     592         161 :                 if (Z_TYPE_PP(tmp) == IS_ARRAY) {
     593         160 :                         int last_len = *len;
     594         160 :                         zend_hash_apply_with_arguments(Z_ARRVAL_PP(tmp) TSRMLS_CC, (apply_func_args_t)_build_trace_args, 2, str, len);
     595         160 :                         if (last_len != *len) {
     596         112 :                                 *len -= 2; /* remove last ', ' */
     597             :                         }
     598             :                 } else {
     599           1 :                         zend_error(E_WARNING, "args element is no array");
     600             :                 }
     601             :         }
     602         164 :         TRACE_APPEND_STR(")\n");
     603         164 :         return ZEND_HASH_APPLY_KEEP;
     604             : }
     605             : /* }}} */
     606             : 
     607             : /* {{{ proto string Exception::getTraceAsString()
     608             :    Obtain the backtrace for the exception as a string (instead of an array) */
     609         130 : ZEND_METHOD(exception, getTraceAsString)
     610             : {
     611             :         zval *trace;
     612             :         char *res, **str, *s_tmp;
     613         130 :         int res_len = 0, *len = &res_len, num = 0;
     614             : 
     615         130 :         DEFAULT_0_PARAMS;
     616             : 
     617         129 :         trace = zend_read_property(default_exception_ce, getThis(), "trace", sizeof("trace")-1, 1 TSRMLS_CC);
     618         129 :         if(Z_TYPE_P(trace) != IS_ARRAY) {
     619           1 :                 RETURN_FALSE;
     620             :         }
     621             : 
     622         128 :         res = estrdup("");
     623         128 :         str = &res;
     624             : 
     625         128 :         zend_hash_apply_with_arguments(Z_ARRVAL_P(trace) TSRMLS_CC, (apply_func_args_t)_build_trace_string, 3, str, len, &num);
     626             : 
     627         128 :         s_tmp = emalloc(1 + MAX_LENGTH_OF_LONG + 7 + 1);
     628         128 :         sprintf(s_tmp, "#%d {main}", num);
     629         128 :         TRACE_APPEND_STRL(s_tmp, strlen(s_tmp));
     630         128 :         efree(s_tmp);
     631             : 
     632         128 :         res[res_len] = '\0';
     633         128 :         RETURN_STRINGL(res, res_len, 0);
     634             : }
     635             : /* }}} */
     636             : 
     637             : /* {{{ proto string Exception::getPrevious()
     638             :    Return previous Exception or NULL. */
     639           4 : ZEND_METHOD(exception, getPrevious)
     640             : {
     641             :         zval *previous;
     642             : 
     643           4 :         DEFAULT_0_PARAMS;
     644             : 
     645           4 :         previous = zend_read_property(default_exception_ce, getThis(), "previous", sizeof("previous")-1, 1 TSRMLS_CC);
     646          16 :         RETURN_ZVAL(previous, 1, 0);
     647             : }
     648             : 
     649     1754473 : int zend_spprintf(char **message, int max_len, char *format, ...) /* {{{ */
     650             : {
     651             :         va_list arg;
     652             :         int len;
     653             : 
     654     1754473 :         va_start(arg, format);
     655     1754473 :         len = zend_vspprintf(message, max_len, format, arg);
     656     1754473 :         va_end(arg);
     657     1754473 :         return len;
     658             : }
     659             : /* }}} */
     660             : 
     661             : /* {{{ proto string Exception::__toString()
     662             :    Obtain the string representation of the Exception object */
     663         118 : ZEND_METHOD(exception, __toString)
     664             : {
     665             :         zval message, file, line, *trace, *exception;
     666             :         char *str, *prev_str;
     667         118 :         int len = 0;
     668             :         zend_fcall_info fci;
     669             :         zval fname;
     670             : 
     671         118 :         DEFAULT_0_PARAMS;
     672             : 
     673         117 :         str = estrndup("", 0);
     674             : 
     675         117 :         exception = getThis();
     676         117 :         ZVAL_STRINGL(&fname, "gettraceasstring", sizeof("gettraceasstring")-1, 1);
     677             : 
     678         357 :         while (exception && Z_TYPE_P(exception) == IS_OBJECT && instanceof_function(Z_OBJCE_P(exception), default_exception_ce TSRMLS_CC)) {
     679         124 :                 prev_str = str;
     680         124 :                 _default_exception_get_entry(exception, "message", sizeof("message")-1, &message TSRMLS_CC);
     681         124 :                 _default_exception_get_entry(exception, "file", sizeof("file")-1, &file TSRMLS_CC);
     682         124 :                 _default_exception_get_entry(exception, "line", sizeof("line")-1, &line TSRMLS_CC);
     683             : 
     684         124 :                 convert_to_string(&message);
     685         123 :                 convert_to_string(&file);
     686         123 :                 convert_to_long(&line);
     687             : 
     688         123 :                 trace = NULL;
     689         123 :                 fci.size = sizeof(fci);
     690         123 :                 fci.function_table = &Z_OBJCE_P(exception)->function_table;
     691         123 :                 fci.function_name = &fname;
     692         123 :                 fci.symbol_table = NULL;
     693         123 :                 fci.object_ptr = exception;
     694         123 :                 fci.retval_ptr_ptr = &trace;
     695         123 :                 fci.param_count = 0;
     696         123 :                 fci.params = NULL;
     697         123 :                 fci.no_separation = 1;
     698             : 
     699         123 :                 zend_call_function(&fci, NULL TSRMLS_CC);
     700             : 
     701         123 :                 if (trace && Z_TYPE_P(trace) != IS_STRING) {
     702           1 :                         zval_ptr_dtor(&trace);
     703           1 :                         trace = NULL;
     704             :                 }
     705             : 
     706         123 :                 if (Z_STRLEN(message) > 0) {
     707         500 :                         len = zend_spprintf(&str, 0, "exception '%s' with message '%s' in %s:%ld\nStack trace:\n%s%s%s",
     708         100 :                                                                 Z_OBJCE_P(exception)->name, Z_STRVAL(message), Z_STRVAL(file), Z_LVAL(line),
     709         300 :                                                                 (trace && Z_STRLEN_P(trace)) ? Z_STRVAL_P(trace) : "#0 {main}\n",
     710             :                                                                 len ? "\n\nNext " : "", prev_str);
     711             :                 } else {
     712         113 :                         len = zend_spprintf(&str, 0, "exception '%s' in %s:%ld\nStack trace:\n%s%s%s",
     713          23 :                                                                 Z_OBJCE_P(exception)->name, Z_STRVAL(file), Z_LVAL(line),
     714          67 :                                                                 (trace && Z_STRLEN_P(trace)) ? Z_STRVAL_P(trace) : "#0 {main}\n",
     715             :                                                                 len ? "\n\nNext " : "", prev_str);
     716             :                 }
     717         123 :                 efree(prev_str);
     718             :                 zval_dtor(&message);
     719             :                 zval_dtor(&file);
     720             :                 zval_dtor(&line);
     721             : 
     722         123 :                 exception = zend_read_property(default_exception_ce, exception, "previous", sizeof("previous")-1, 0 TSRMLS_CC);
     723             : 
     724         123 :                 if (trace) {
     725         122 :                         zval_ptr_dtor(&trace);
     726             :                 }
     727             : 
     728             :         }
     729             :         zval_dtor(&fname);
     730             : 
     731             :         /* We store the result in the private property string so we can access
     732             :          * the result in uncaught exception handlers without memleaks. */
     733         116 :         zend_update_property_string(default_exception_ce, getThis(), "string", sizeof("string")-1, str TSRMLS_CC);
     734             : 
     735         116 :         RETURN_STRINGL(str, len, 0);
     736             : }
     737             : /* }}} */
     738             : 
     739             : /* {{{ internal structs */
     740             : /* All functions that may be used in uncaught exception handlers must be final
     741             :  * and must not throw exceptions. Otherwise we would need a facility to handle
     742             :  * such exceptions in that handler.
     743             :  * Also all getXY() methods are final because thy serve as read only access to
     744             :  * their corresponding properties, no more, no less. If after all you need to
     745             :  * override somthing then it is method __toString().
     746             :  * And never try to change the state of exceptions and never implement anything
     747             :  * that gives the user anything to accomplish this.
     748             :  */
     749             : ZEND_BEGIN_ARG_INFO_EX(arginfo_exception___construct, 0, 0, 0)
     750             :         ZEND_ARG_INFO(0, message)
     751             :         ZEND_ARG_INFO(0, code)
     752             :         ZEND_ARG_INFO(0, previous)
     753             : ZEND_END_ARG_INFO()
     754             : 
     755             : const static zend_function_entry default_exception_functions[] = {
     756             :         ZEND_ME(exception, __clone, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
     757             :         ZEND_ME(exception, __construct, arginfo_exception___construct, ZEND_ACC_PUBLIC)
     758             :         ZEND_ME(exception, __wakeup, NULL, ZEND_ACC_PUBLIC)
     759             :         ZEND_ME(exception, getMessage, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
     760             :         ZEND_ME(exception, getCode, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
     761             :         ZEND_ME(exception, getFile, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
     762             :         ZEND_ME(exception, getLine, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
     763             :         ZEND_ME(exception, getTrace, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
     764             :         ZEND_ME(exception, getPrevious, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
     765             :         ZEND_ME(exception, getTraceAsString, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
     766             :         ZEND_ME(exception, __toString, NULL, 0)
     767             :         {NULL, NULL, NULL}
     768             : };
     769             : 
     770             : ZEND_BEGIN_ARG_INFO_EX(arginfo_error_exception___construct, 0, 0, 0)
     771             :         ZEND_ARG_INFO(0, message)
     772             :         ZEND_ARG_INFO(0, code)
     773             :         ZEND_ARG_INFO(0, severity)
     774             :         ZEND_ARG_INFO(0, filename)
     775             :         ZEND_ARG_INFO(0, lineno)
     776             :         ZEND_ARG_INFO(0, previous)
     777             : ZEND_END_ARG_INFO()
     778             : 
     779             : static const zend_function_entry error_exception_functions[] = {
     780             :         ZEND_ME(error_exception, __construct, arginfo_error_exception___construct, ZEND_ACC_PUBLIC)
     781             :         ZEND_ME(error_exception, getSeverity, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
     782             :         {NULL, NULL, NULL}
     783             : };
     784             : /* }}} */
     785             : 
     786       20286 : void zend_register_default_exception(TSRMLS_D) /* {{{ */
     787             : {
     788             :         zend_class_entry ce;
     789             : 
     790       20286 :         INIT_CLASS_ENTRY(ce, "Exception", default_exception_functions);
     791       20286 :         default_exception_ce = zend_register_internal_class(&ce TSRMLS_CC);
     792       20286 :         default_exception_ce->create_object = zend_default_exception_new;
     793       20286 :         memcpy(&default_exception_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
     794       20286 :         default_exception_handlers.clone_obj = NULL;
     795             : 
     796       20286 :         zend_declare_property_string(default_exception_ce, "message", sizeof("message")-1, "", ZEND_ACC_PROTECTED TSRMLS_CC);
     797       20286 :         zend_declare_property_string(default_exception_ce, "string", sizeof("string")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC);
     798       20286 :         zend_declare_property_long(default_exception_ce, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED TSRMLS_CC);
     799       20286 :         zend_declare_property_null(default_exception_ce, "file", sizeof("file")-1, ZEND_ACC_PROTECTED TSRMLS_CC);
     800       20286 :         zend_declare_property_null(default_exception_ce, "line", sizeof("line")-1, ZEND_ACC_PROTECTED TSRMLS_CC);
     801       20286 :         zend_declare_property_null(default_exception_ce, "trace", sizeof("trace")-1, ZEND_ACC_PRIVATE TSRMLS_CC);
     802       20286 :         zend_declare_property_null(default_exception_ce, "previous", sizeof("previous")-1, ZEND_ACC_PRIVATE TSRMLS_CC);
     803             : 
     804       20286 :         INIT_CLASS_ENTRY(ce, "ErrorException", error_exception_functions);
     805       20286 :         error_exception_ce = zend_register_internal_class_ex(&ce, default_exception_ce, NULL TSRMLS_CC);
     806       20286 :         error_exception_ce->create_object = zend_error_exception_new;
     807       20286 :         zend_declare_property_long(error_exception_ce, "severity", sizeof("severity")-1, E_ERROR, ZEND_ACC_PROTECTED TSRMLS_CC);
     808       20286 : }
     809             : /* }}} */
     810             : 
     811      122191 : ZEND_API zend_class_entry *zend_exception_get_default(TSRMLS_D) /* {{{ */
     812             : {
     813      122191 :         return default_exception_ce;
     814             : }
     815             : /* }}} */
     816             : 
     817           0 : ZEND_API zend_class_entry *zend_get_error_exception(TSRMLS_D) /* {{{ */
     818             : {
     819           0 :         return error_exception_ce;
     820             : }
     821             : /* }}} */
     822             : 
     823         871 : ZEND_API zval * zend_throw_exception(zend_class_entry *exception_ce, char *message, long code TSRMLS_DC) /* {{{ */
     824             : {
     825             :         zval *ex;
     826             : 
     827         871 :         MAKE_STD_ZVAL(ex);
     828         871 :         if (exception_ce) {
     829         755 :                 if (!instanceof_function(exception_ce, default_exception_ce TSRMLS_CC)) {
     830           0 :                         zend_error(E_NOTICE, "Exceptions must be derived from the Exception base class");
     831           0 :                         exception_ce = default_exception_ce;
     832             :                 }
     833             :         } else {
     834         116 :                 exception_ce = default_exception_ce;
     835             :         }
     836         871 :         object_init_ex(ex, exception_ce);
     837             : 
     838             : 
     839         871 :         if (message) {
     840         871 :                 zend_update_property_string(default_exception_ce, ex, "message", sizeof("message")-1, message TSRMLS_CC);
     841             :         }
     842         871 :         if (code) {
     843          85 :                 zend_update_property_long(default_exception_ce, ex, "code", sizeof("code")-1, code TSRMLS_CC);
     844             :         }
     845             : 
     846         871 :         zend_throw_exception_internal(ex TSRMLS_CC);
     847         871 :         return ex;
     848             : }
     849             : /* }}} */
     850             : 
     851         579 : ZEND_API zval * zend_throw_exception_ex(zend_class_entry *exception_ce, long code TSRMLS_DC, char *format, ...) /* {{{ */
     852             : {
     853             :         va_list arg;
     854             :         char *message;
     855             :         zval *zexception;
     856             : 
     857         579 :         va_start(arg, format);
     858         579 :         zend_vspprintf(&message, 0, format, arg);
     859         579 :         va_end(arg);
     860         579 :         zexception = zend_throw_exception(exception_ce, message, code TSRMLS_CC);
     861         579 :         efree(message);
     862         579 :         return zexception;
     863             : }
     864             : /* }}} */
     865             : 
     866         142 : ZEND_API zval * zend_throw_error_exception(zend_class_entry *exception_ce, char *message, long code, int severity TSRMLS_DC) /* {{{ */
     867             : {
     868         142 :         zval *ex = zend_throw_exception(exception_ce, message, code TSRMLS_CC);
     869         142 :         zend_update_property_long(default_exception_ce, ex, "severity", sizeof("severity")-1, severity TSRMLS_CC);
     870         142 :         return ex;
     871             : }
     872             : /* }}} */
     873             : 
     874          91 : static void zend_error_va(int type, const char *file, uint lineno, const char *format, ...) /* {{{ */
     875             : {
     876             :         va_list args;
     877             : 
     878          91 :         va_start(args, format);
     879          91 :         zend_error_cb(type, file, lineno, format, args);
     880           3 :         va_end(args);
     881           3 : }
     882             : /* }}} */
     883             : 
     884             : /* This function doesn't return if it uses E_ERROR */
     885          92 : ZEND_API void zend_exception_error(zval *exception, int severity TSRMLS_DC) /* {{{ */
     886             : {
     887          92 :         zend_class_entry *ce_exception = Z_OBJCE_P(exception);
     888          92 :         if (instanceof_function(ce_exception, default_exception_ce TSRMLS_CC)) {
     889             :                 zval *str, *file, *line;
     890             : 
     891          92 :                 EG(exception) = NULL;
     892             : 
     893          92 :                 zend_call_method_with_0_params(&exception, ce_exception, NULL, "__tostring", &str);
     894          91 :                 if (!EG(exception)) {
     895          91 :                         if (Z_TYPE_P(str) != IS_STRING) {
     896           0 :                                 zend_error(E_WARNING, "%s::__toString() must return a string", ce_exception->name);
     897             :                         } else {
     898          91 :                                 zend_update_property_string(default_exception_ce, exception, "string", sizeof("string")-1, EG(exception) ? ce_exception->name : Z_STRVAL_P(str) TSRMLS_CC);
     899             :                         }
     900             :                 }
     901          91 :                 zval_ptr_dtor(&str);
     902             : 
     903          91 :                 if (EG(exception)) {
     904             :                         /* do the best we can to inform about the inner exception */
     905           0 :                         if (instanceof_function(ce_exception, default_exception_ce TSRMLS_CC)) {
     906           0 :                                 file = zend_read_property(default_exception_ce, EG(exception), "file", sizeof("file")-1, 1 TSRMLS_CC);
     907           0 :                                 line = zend_read_property(default_exception_ce, EG(exception), "line", sizeof("line")-1, 1 TSRMLS_CC);
     908             : 
     909           0 :                                 convert_to_string(file);
     910           0 :                                 file = (Z_STRLEN_P(file) > 0) ? file : NULL;
     911           0 :                                 line = (Z_TYPE_P(line) == IS_LONG) ? line : NULL;
     912             :                         } else {
     913           0 :                                 file = NULL;
     914           0 :                                 line = NULL;
     915             :                         }
     916           0 :                         zend_error_va(E_WARNING, file ? Z_STRVAL_P(file) : NULL, line ? Z_LVAL_P(line) : 0, "Uncaught %s in exception handling during call to %s::__tostring()", Z_OBJCE_P(EG(exception))->name, ce_exception->name);
     917             :                 }
     918             : 
     919          91 :                 str = zend_read_property(default_exception_ce, exception, "string", sizeof("string")-1, 1 TSRMLS_CC);
     920          91 :                 file = zend_read_property(default_exception_ce, exception, "file", sizeof("file")-1, 1 TSRMLS_CC);
     921          91 :                 line = zend_read_property(default_exception_ce, exception, "line", sizeof("line")-1, 1 TSRMLS_CC);
     922             : 
     923          91 :                 convert_to_string(str);
     924          91 :                 convert_to_string(file);
     925          91 :                 convert_to_long(line);
     926             : 
     927          91 :                 zend_error_va(severity, (Z_STRLEN_P(file) > 0) ? Z_STRVAL_P(file) : NULL, Z_LVAL_P(line), "Uncaught %s\n  thrown", Z_STRVAL_P(str));
     928             :         } else {
     929           0 :                 zend_error(severity, "Uncaught exception '%s'", ce_exception->name);
     930             :         }
     931           3 : }
     932             : /* }}} */
     933             : 
     934         327 : ZEND_API void zend_throw_exception_object(zval *exception TSRMLS_DC) /* {{{ */
     935             : {
     936             :         zend_class_entry *exception_ce;
     937             : 
     938         327 :         if (exception == NULL || Z_TYPE_P(exception) != IS_OBJECT) {
     939           0 :                 zend_error(E_ERROR, "Need to supply an object when throwing an exception");
     940             :         }
     941             : 
     942         327 :         exception_ce = Z_OBJCE_P(exception);
     943             : 
     944         327 :         if (!exception_ce || !instanceof_function(exception_ce, default_exception_ce TSRMLS_CC)) {
     945           1 :                 zend_error(E_ERROR, "Exceptions must be valid objects derived from the Exception base class");
     946             :         }
     947         326 :         zend_throw_exception_internal(exception TSRMLS_CC);
     948         326 : }
     949             : /* }}} */
     950             : 
     951             : /*
     952             :  * Local variables:
     953             :  * tab-width: 4
     954             :  * c-basic-offset: 4
     955             :  * indent-tabs-mode: t
     956             :  * End:
     957             :  */

Generated by: LCOV version 1.10

Generated at Thu, 27 Aug 2015 06:06:07 +0000 (4 days ago)

Copyright © 2005-2015 The PHP Group
All rights reserved.