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: 386 429 90.0 %
Date: 2015-07-05 Functions: 38 41 92.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2015 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             : #include "zend_smart_str.h"
      32             : 
      33             : ZEND_API zend_class_entry *zend_ce_throwable;
      34             : 
      35             : static zend_class_entry *default_exception_ce;
      36             : static zend_class_entry *error_exception_ce;
      37             : static zend_class_entry *error_ce;
      38             : static zend_class_entry *parse_error_ce;
      39             : static zend_class_entry *type_error_ce;
      40             : static zend_object_handlers default_exception_handlers;
      41             : ZEND_API void (*zend_throw_exception_hook)(zval *ex);
      42             : 
      43             : /* {{{ zend_implement_throwable */
      44      589400 : static int zend_implement_throwable(zend_class_entry *interface, zend_class_entry *class_type)
      45             : {
      46      589400 :         if (instanceof_function(class_type, default_exception_ce) || instanceof_function(class_type, error_ce)) {
      47      589399 :                 return SUCCESS;
      48             :         }
      49           4 :         zend_error_noreturn(E_ERROR, "Class %s cannot implement interface %s, extend %s or %s instead",
      50           1 :                 class_type->name->val,
      51           1 :                 interface->name->val,
      52           1 :                 default_exception_ce->name->val,
      53           1 :                 error_ce->name->val);
      54             :         return FAILURE;
      55             : }
      56             : /* }}} */
      57             : 
      58       10207 : static inline zend_class_entry *zend_get_exception_base(zval *object)
      59             : {
      60       10207 :         return instanceof_function(Z_OBJCE_P(object), default_exception_ce) ? default_exception_ce : error_ce;
      61             : }
      62             : 
      63        2479 : void zend_exception_set_previous(zend_object *exception, zend_object *add_previous)
      64             : {
      65             :     zval tmp, *previous, zv, *pzv, rv;
      66             :         zend_class_entry *base_ce;
      67             : 
      68        2479 :         if (exception == add_previous || !add_previous || !exception) {
      69        2463 :                 return;
      70             :         }
      71          16 :         ZVAL_OBJ(&tmp, add_previous);
      72          16 :         if (!instanceof_function(Z_OBJCE(tmp), zend_ce_throwable)) {
      73           0 :                 zend_error_noreturn(E_CORE_ERROR, "Previous exception must implement Throwable");
      74             :                 return;
      75             :         }
      76          16 :         ZVAL_OBJ(&zv, exception);
      77          16 :         pzv = &zv;
      78             :         do {
      79          16 :                 base_ce = zend_get_exception_base(pzv);
      80          16 :                 previous = zend_read_property(base_ce, pzv, "previous", sizeof("previous")-1, 1, &rv);
      81          16 :                 if (Z_TYPE_P(previous) == IS_NULL) {
      82          16 :                         zend_update_property(base_ce, pzv, "previous", sizeof("previous")-1, &tmp);
      83          16 :                         GC_REFCOUNT(add_previous)--;
      84          16 :                         return;
      85             :                 }
      86           0 :                 pzv = previous;
      87           0 :         } while (pzv && Z_OBJ_P(pzv) != add_previous);
      88             : }
      89             : 
      90         637 : void zend_exception_save(void) /* {{{ */
      91             : {
      92         637 :         if (EG(prev_exception)) {
      93           4 :                 zend_exception_set_previous(EG(exception), EG(prev_exception));
      94             :         }
      95         637 :         if (EG(exception)) {
      96          16 :                 EG(prev_exception) = EG(exception);
      97             :         }
      98         637 :         EG(exception) = NULL;
      99         637 : }
     100             : /* }}} */
     101             : 
     102       22066 : void zend_exception_restore(void) /* {{{ */
     103             : {
     104       22066 :         if (EG(prev_exception)) {
     105          16 :                 if (EG(exception)) {
     106           3 :                         zend_exception_set_previous(EG(exception), EG(prev_exception));
     107             :                 } else {
     108          13 :                         EG(exception) = EG(prev_exception);
     109             :                 }
     110          16 :                 EG(prev_exception) = NULL;
     111             :         }
     112       22066 : }
     113             : /* }}} */
     114             : 
     115        4620 : ZEND_API void zend_throw_exception_internal(zval *exception) /* {{{ */
     116             : {
     117             : #ifdef HAVE_DTRACE
     118             :         if (DTRACE_EXCEPTION_THROWN_ENABLED()) {
     119             :                 if (exception != NULL) {
     120             :                         DTRACE_EXCEPTION_THROWN(Z_OBJ_P(exception)->ce->name->val);
     121             :                 } else {
     122             :                         DTRACE_EXCEPTION_THROWN(NULL);
     123             :                 }
     124             :         }
     125             : #endif /* HAVE_DTRACE */
     126             : 
     127        4620 :         if (exception != NULL) {
     128        2467 :                 zend_object *previous = EG(exception);
     129        2467 :                 zend_exception_set_previous(Z_OBJ_P(exception), EG(exception));
     130        2467 :                 EG(exception) = Z_OBJ_P(exception);
     131        2467 :                 if (previous) {
     132           8 :                         return;
     133             :                 }
     134             :         }
     135        4612 :         if (!EG(current_execute_data)) {
     136          39 :                 if (exception && Z_OBJCE_P(exception) == parse_error_ce) {
     137          33 :                         return;
     138             :                 }
     139           6 :                 if(EG(exception)) {
     140           6 :                         zend_exception_error(EG(exception), E_ERROR);
     141             :                 }
     142           0 :                 zend_error_noreturn(E_CORE_ERROR, "Exception thrown without a stack frame");
     143             :         }
     144             : 
     145        4573 :         if (zend_throw_exception_hook) {
     146           0 :                 zend_throw_exception_hook(exception);
     147             :         }
     148             : 
     149       12300 :         if (!EG(current_execute_data)->func ||
     150        4568 :             !ZEND_USER_CODE(EG(current_execute_data)->func->common.type) ||
     151        3159 :             EG(current_execute_data)->opline->opcode == ZEND_HANDLE_EXCEPTION) {
     152             :                 /* no need to rethrow the exception */
     153        1443 :                 return;
     154             :         }
     155        3130 :         EG(opline_before_exception) = EG(current_execute_data)->opline;
     156        3130 :         EG(current_execute_data)->opline = EG(exception_op);
     157             : }
     158             : /* }}} */
     159             : 
     160         103 : ZEND_API void zend_clear_exception(void) /* {{{ */
     161             : {
     162         103 :         if (EG(prev_exception)) {
     163             : 
     164           0 :                 OBJ_RELEASE(EG(prev_exception));
     165           0 :                 EG(prev_exception) = NULL;
     166             :         }
     167         103 :         if (!EG(exception)) {
     168          91 :                 return;
     169             :         }
     170          12 :         OBJ_RELEASE(EG(exception));
     171          12 :         EG(exception) = NULL;
     172          12 :         EG(current_execute_data)->opline = EG(opline_before_exception);
     173             : #if ZEND_DEBUG
     174             :         EG(opline_before_exception) = NULL;
     175             : #endif
     176             : }
     177             : /* }}} */
     178             : 
     179        2895 : static zend_object *zend_default_exception_new_ex(zend_class_entry *class_type, int skip_top_traces) /* {{{ */
     180             : {
     181             :         zval obj;
     182             :         zend_object *object;
     183             :         zval trace;
     184             :         zend_class_entry *base_ce;
     185             :         zend_string *filename;
     186             : 
     187        2895 :         Z_OBJ(obj) = object = zend_objects_new(class_type);
     188        2895 :         Z_OBJ_HT(obj) = &default_exception_handlers;
     189             : 
     190        2895 :         object_properties_init(object, class_type);
     191             : 
     192        2895 :         if (EG(current_execute_data)) {
     193        2862 :                 zend_fetch_debug_backtrace(&trace, skip_top_traces, 0, 0);
     194             :         } else {
     195          33 :                 array_init(&trace);
     196             :         }
     197             :         Z_SET_REFCOUNT(trace, 0);
     198             :         
     199        2895 :         base_ce = zend_get_exception_base(&obj);
     200             : 
     201        5731 :         if (EXPECTED(class_type != parse_error_ce || !(filename = zend_get_compiled_filename()))) {
     202        2836 :                 zend_update_property_string(base_ce, &obj, "file", sizeof("file")-1, zend_get_executed_filename());
     203        2836 :                 zend_update_property_long(base_ce, &obj, "line", sizeof("line")-1, zend_get_executed_lineno());
     204             :         } else {
     205          59 :                 zend_update_property_string(base_ce, &obj, "file", sizeof("file")-1, filename->val);
     206          59 :                 zend_update_property_long(base_ce, &obj, "line", sizeof("line")-1, zend_get_compiled_lineno());
     207             :         }
     208        2895 :         zend_update_property(base_ce, &obj, "trace", sizeof("trace")-1, &trace);
     209             : 
     210        2895 :         return object;
     211             : }
     212             : /* }}} */
     213             : 
     214        2892 : static zend_object *zend_default_exception_new(zend_class_entry *class_type) /* {{{ */
     215             : {
     216        2892 :         return zend_default_exception_new_ex(class_type, 0);
     217             : }
     218             : /* }}} */
     219             : 
     220           3 : static zend_object *zend_error_exception_new(zend_class_entry *class_type) /* {{{ */
     221             : {
     222           3 :         return zend_default_exception_new_ex(class_type, 2);
     223             : }
     224             : /* }}} */
     225             : 
     226             : /* {{{ proto Exception|Error Exception|Error::__clone()
     227             :    Clone the exception object */
     228           0 : ZEND_METHOD(exception, __clone)
     229             : {
     230             :         /* Should never be executable */
     231           0 :         zend_throw_exception(NULL, "Cannot clone object using __clone()", 0);
     232           0 : }
     233             : /* }}} */
     234             : 
     235             : /* {{{ proto Exception|Error::__construct(string message, int code [, Throwable previous])
     236             :    Exception constructor */
     237         372 : ZEND_METHOD(exception, __construct)
     238             : {
     239         372 :         zend_string *message = NULL;
     240         372 :         zend_long   code = 0;
     241         372 :         zval  *object, *previous = NULL;
     242             :         zend_class_entry *base_ce;
     243         372 :         int    argc = ZEND_NUM_ARGS();
     244             : 
     245         372 :         object = getThis();
     246         372 :         base_ce = zend_get_exception_base(object);
     247             : 
     248         372 :         if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc, "|SlO!", &message, &code, &previous, zend_ce_throwable) == FAILURE) {
     249             :                 zend_class_entry *ce;
     250             : 
     251           4 :                 if (execute_data->called_scope) {
     252           4 :                         ce = execute_data->called_scope;
     253             :                 } else {
     254           0 :                         ce = base_ce;
     255             :                 }
     256           4 :                 zend_error(E_EXCEPTION | E_ERROR, "Wrong parameters for %s([string $message [, long $code [, Throwable $previous = NULL]]])", ce->name->val);
     257           4 :                 return;
     258             :         }
     259             : 
     260         368 :         if (message) {
     261         268 :                 zend_update_property_str(base_ce, object, "message", sizeof("message")-1, message);
     262             :         }
     263             : 
     264         368 :         if (code) {
     265           6 :                 zend_update_property_long(base_ce, object, "code", sizeof("code")-1, code);
     266             :         }
     267             : 
     268         368 :         if (previous) {
     269           5 :                 zend_update_property(base_ce, object, "previous", sizeof("previous")-1, previous);
     270             :         }
     271             : }
     272             : /* }}} */
     273             : 
     274             : /* {{{ proto ErrorException::__construct(string message, int code, int severity [, string filename [, int lineno [, Throwable previous]]])
     275             :    ErrorException constructor */
     276           3 : ZEND_METHOD(error_exception, __construct)
     277             : {
     278           3 :         char  *message = NULL, *filename = NULL;
     279           3 :         zend_long   code = 0, severity = E_ERROR, lineno;
     280           3 :         zval  *object, *previous = NULL;
     281           3 :         int    argc = ZEND_NUM_ARGS();
     282             :         size_t message_len, filename_len;
     283             : 
     284           3 :         if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc, "|sllslO!", &message, &message_len, &code, &severity, &filename, &filename_len, &lineno, &previous, zend_ce_throwable) == FAILURE) {
     285             :                 zend_class_entry *ce;
     286             : 
     287           1 :                 if (execute_data->called_scope) {
     288           1 :                         ce = execute_data->called_scope;
     289             :                 } else {
     290           0 :                         ce = error_exception_ce;
     291             :                 }
     292           1 :                 zend_error(E_EXCEPTION | E_ERROR, "Wrong parameters for %s([string $message [, long $code, [ long $severity, [ string $filename, [ long $lineno  [, Throwable $previous = NULL]]]]]])", ce->name->val);
     293           1 :                 return;
     294             :         }
     295             : 
     296           2 :         object = getThis();
     297             : 
     298           2 :         if (message) {
     299           2 :                 zend_update_property_string(default_exception_ce, object, "message", sizeof("message")-1, message);
     300             :         }
     301             : 
     302           2 :         if (code) {
     303           1 :                 zend_update_property_long(default_exception_ce, object, "code", sizeof("code")-1, code);
     304             :         }
     305             : 
     306           2 :         if (previous) {
     307           0 :                 zend_update_property(default_exception_ce, object, "previous", sizeof("previous")-1, previous);
     308             :         }
     309             : 
     310           2 :         zend_update_property_long(error_exception_ce, object, "severity", sizeof("severity")-1, severity);
     311             : 
     312           2 :         if (argc >= 4) {
     313           2 :             zend_update_property_string(default_exception_ce, object, "file", sizeof("file")-1, filename);
     314           2 :         if (argc < 5) {
     315           0 :             lineno = 0; /* invalidate lineno */
     316             :         }
     317           2 :                 zend_update_property_long(default_exception_ce, object, "line", sizeof("line")-1, lineno);
     318             :         }
     319             : }
     320             : /* }}} */
     321             : 
     322             : #define DEFAULT_0_PARAMS \
     323             :         if (zend_parse_parameters_none() == FAILURE) { \
     324             :                 return; \
     325             :         }
     326             : 
     327             : #define GET_PROPERTY(object, name) \
     328             :         zend_read_property(zend_get_exception_base(object), (object), name, sizeof(name) - 1, 0, &rv)
     329             : #define GET_PROPERTY_SILENT(object, name) \
     330             :         zend_read_property(zend_get_exception_base(object), (object), name, sizeof(name) - 1, 1, &rv)
     331             : 
     332             : /* {{{ proto string Exception|Error::getFile()
     333             :    Get the file in which the exception occurred */
     334          47 : ZEND_METHOD(exception, getFile)
     335             : {
     336             :         zval rv;
     337             : 
     338          47 :         DEFAULT_0_PARAMS;
     339             : 
     340          46 :         ZVAL_COPY(return_value, GET_PROPERTY(getThis(), "file"));
     341             : }
     342             : /* }}} */
     343             : 
     344             : /* {{{ proto int Exception|Error::getLine()
     345             :    Get the line in which the exception occurred */
     346          60 : ZEND_METHOD(exception, getLine)
     347             : {
     348             :         zval rv;
     349             : 
     350          60 :         DEFAULT_0_PARAMS;
     351             : 
     352          59 :         ZVAL_COPY(return_value, GET_PROPERTY(getThis(), "line"));
     353             : }
     354             : /* }}} */
     355             : 
     356             : /* {{{ proto string Exception|Error::getMessage()
     357             :    Get the exception message */
     358        1607 : ZEND_METHOD(exception, getMessage)
     359             : {
     360             :         zval rv;
     361             : 
     362        1607 :         DEFAULT_0_PARAMS;
     363             : 
     364        1606 :         ZVAL_COPY(return_value, GET_PROPERTY(getThis(), "message"));
     365             : }
     366             : /* }}} */
     367             : 
     368             : /* {{{ proto int Exception|Error::getCode()
     369             :    Get the exception code */
     370          70 : ZEND_METHOD(exception, getCode)
     371             : {
     372             :         zval rv;
     373             : 
     374          70 :         DEFAULT_0_PARAMS;
     375             : 
     376          69 :         ZVAL_COPY(return_value, GET_PROPERTY(getThis(), "code"));
     377             : }
     378             : /* }}} */
     379             : 
     380             : /* {{{ proto array Exception|Error::getTrace()
     381             :    Get the stack trace for the location in which the exception occurred */
     382           6 : ZEND_METHOD(exception, getTrace)
     383             : {
     384             :         zval rv;
     385             : 
     386           6 :         DEFAULT_0_PARAMS;
     387             : 
     388           5 :         ZVAL_COPY(return_value, GET_PROPERTY(getThis(), "trace"));
     389             : }
     390             : /* }}} */
     391             : 
     392             : /* {{{ proto int ErrorException::getSeverity()
     393             :    Get the exception severity */
     394           0 : ZEND_METHOD(error_exception, getSeverity)
     395             : {
     396             :         zval rv;
     397             : 
     398           0 :         DEFAULT_0_PARAMS;
     399             : 
     400           0 :         ZVAL_COPY(return_value, GET_PROPERTY(getThis(), "severity"));
     401             : }
     402             : /* }}} */
     403             : 
     404             : #define TRACE_APPEND_KEY(key) do {                                          \
     405             :                 tmp = zend_hash_str_find(ht, key, sizeof(key)-1);                   \
     406             :                 if (tmp) {                                                          \
     407             :                         if (Z_TYPE_P(tmp) != IS_STRING) {                               \
     408             :                                 zend_error(E_WARNING, "Value for %s is no string", key);    \
     409             :                                 smart_str_appends(str, "[unknown]");                        \
     410             :                         } else {                                                        \
     411             :                                 smart_str_append(str, Z_STR_P(tmp));   \
     412             :                         }                                                               \
     413             :                 } \
     414             :         } while (0)
     415             : 
     416             : /* Windows uses VK_ESCAPE instead of \e */
     417             : #ifndef VK_ESCAPE
     418             : #define VK_ESCAPE '\e'
     419             : #endif
     420             : 
     421         154 : static size_t compute_escaped_string_len(const char *s, size_t l) {
     422         154 :         size_t i, len = l;
     423        1523 :         for (i = 0; i < l; ++i) {
     424        1369 :                 char c = s[i];
     425        1369 :                 if (c == '\n' || c == '\r' || c == '\t' ||
     426             :                         c == '\f' || c == '\v' || c == '\\' || c == VK_ESCAPE) {
     427           0 :                         len += 1;
     428        1369 :                 } else if (c < 32 || c > 126) {
     429          21 :                         len += 3;
     430             :                 }
     431             :         }
     432         154 :         return len;
     433             : }
     434             : 
     435         154 : static void smart_str_append_escaped(smart_str *str, const char *s, size_t l) {
     436             :         char *res;
     437         154 :         size_t i, len = compute_escaped_string_len(s, l);
     438             : 
     439             :         smart_str_alloc(str, len, 0);
     440         154 :         res = &str->s->val[str->s->len];
     441         154 :         str->s->len += len;
     442             : 
     443        1523 :         for (i = 0; i < l; ++i) {
     444        1369 :                 unsigned char c = s[i];
     445        1390 :                 if (c < 32 || c == '\\' || c > 126) {
     446          21 :                         *res++ = '\\';
     447          21 :                         switch (c) {
     448           0 :                                 case '\n': *res++ = 'n'; break;
     449           0 :                                 case '\r': *res++ = 'r'; break;
     450           0 :                                 case '\t': *res++ = 't'; break;
     451           0 :                                 case '\f': *res++ = 'f'; break;
     452           0 :                                 case '\v': *res++ = 'v'; break;
     453           0 :                                 case '\\': *res++ = '\\'; break;
     454           0 :                                 case VK_ESCAPE: *res++ = 'e'; break;
     455             :                                 default:
     456          21 :                                         *res++ = 'x';
     457          21 :                                         if ((c >> 4) < 10) {
     458          11 :                                                 *res++ = (c >> 4) + '0';
     459             :                                         } else {
     460          10 :                                                 *res++ = (c >> 4) + 'A' - 10;
     461             :                                         }
     462          21 :                                         if ((c & 0xf) < 10) {
     463          21 :                                                 *res++ = (c & 0xf) + '0';
     464             :                                         } else {
     465           0 :                                                 *res++ = (c & 0xf) + 'A' - 10;
     466             :                                         }
     467             :                         }
     468             :                 } else {
     469        1348 :                         *res++ = c;
     470             :                 }
     471             :         }
     472         154 : }
     473             : 
     474         377 : static void _build_trace_args(zval *arg, smart_str *str) /* {{{ */
     475             : {
     476             :         /* the trivial way would be to do
     477             :          * convert_to_string_ex(arg);
     478             :          * append it and kill the now tmp arg.
     479             :          * but that could cause some E_NOTICE and also damn long lines.
     480             :          */
     481             : 
     482         377 :         ZVAL_DEREF(arg);
     483         377 :         switch (Z_TYPE_P(arg)) {
     484             :                 case IS_NULL:
     485             :                         smart_str_appends(str, "NULL, ");
     486          15 :                         break;
     487             :                 case IS_STRING:
     488             :                         smart_str_appendc(str, '\'');
     489         154 :                         smart_str_append_escaped(str, Z_STRVAL_P(arg), MIN(Z_STRLEN_P(arg), 15));
     490         154 :                         if (Z_STRLEN_P(arg) > 15) {
     491             :                                 smart_str_appends(str, "...', ");
     492             :                         } else {
     493             :                                 smart_str_appends(str, "', ");
     494             :                         }
     495         154 :                         break;
     496             :                 case IS_FALSE:
     497             :                         smart_str_appends(str, "false, ");
     498           9 :                         break;
     499             :                 case IS_TRUE:
     500             :                         smart_str_appends(str, "true, ");
     501           1 :                         break;
     502             :                 case IS_RESOURCE:
     503             :                         smart_str_appends(str, "Resource id #");
     504           1 :                         smart_str_append_long(str, Z_RES_HANDLE_P(arg));
     505             :                         smart_str_appends(str, ", ");
     506           1 :                         break;
     507             :                 case IS_LONG:
     508          89 :                         smart_str_append_long(str, Z_LVAL_P(arg));
     509             :                         smart_str_appends(str, ", ");
     510          89 :                         break;
     511             :                 case IS_DOUBLE: {
     512           5 :                         double dval = Z_DVAL_P(arg);
     513           5 :                         char *s_tmp = emalloc(MAX_LENGTH_OF_DOUBLE + EG(precision) + 1);
     514           5 :                         int l_tmp = zend_sprintf(s_tmp, "%.*G", (int) EG(precision), dval);  /* SAFE */
     515           5 :                         smart_str_appendl(str, s_tmp, l_tmp);
     516             :                         smart_str_appends(str, ", ");
     517           5 :                         efree(s_tmp);
     518           5 :                         break;
     519             :                 }
     520             :                 case IS_ARRAY:
     521             :                         smart_str_appends(str, "Array, ");
     522          48 :                         break;
     523             :                 case IS_OBJECT:
     524             :                         smart_str_appends(str, "Object(");
     525          55 :                         smart_str_append(str, Z_OBJCE_P(arg)->name);
     526             :                         smart_str_appends(str, "), ");
     527             :                         break;
     528             :         }
     529         377 : }
     530             : /* }}} */
     531             : 
     532         390 : static void _build_trace_string(smart_str *str, HashTable *ht, uint32_t num) /* {{{ */
     533             : {
     534             :         zval *file, *tmp;
     535             : 
     536             :         smart_str_appendc(str, '#');
     537         390 :         smart_str_append_long(str, num);
     538             :         smart_str_appendc(str, ' ');
     539             : 
     540         390 :         file = zend_hash_str_find(ht, "file", sizeof("file")-1);
     541         390 :         if (file) {
     542         326 :                 if (Z_TYPE_P(file) != IS_STRING) {
     543           1 :                         zend_error(E_WARNING, "Function name is no string");
     544             :                         smart_str_appends(str, "[unknown function]");
     545             :                 } else{
     546             :                         zend_long line;
     547         325 :                         tmp = zend_hash_str_find(ht, "line", sizeof("line")-1);
     548         325 :                         if (tmp) {
     549         325 :                                 if (Z_TYPE_P(tmp) == IS_LONG) {
     550         325 :                                         line = Z_LVAL_P(tmp);
     551             :                                 } else {
     552           0 :                                         zend_error(E_WARNING, "Line is no long");
     553           0 :                                         line = 0;
     554             :                                 }
     555             :                         } else {
     556           0 :                                 line = 0;
     557             :                         }
     558         325 :                         smart_str_append(str, Z_STR_P(file));
     559             :                         smart_str_appendc(str, '(');
     560             :                         smart_str_append_long(str, line);
     561             :                         smart_str_appends(str, "): ");
     562             :                 }
     563             :         } else {
     564             :                 smart_str_appends(str, "[internal function]: ");
     565             :         }
     566         785 :         TRACE_APPEND_KEY("class");
     567         785 :         TRACE_APPEND_KEY("type");
     568        1167 :         TRACE_APPEND_KEY("function");
     569             :         smart_str_appendc(str, '(');
     570         390 :         tmp = zend_hash_str_find(ht, "args", sizeof("args")-1);
     571         390 :         if (tmp) {
     572         385 :                 if (Z_TYPE_P(tmp) == IS_ARRAY) {
     573         384 :                         size_t last_len = str->s->len;
     574             :                         zval *arg;
     575             : 
     576        1138 :                         ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(tmp), arg) {
     577         377 :                                 _build_trace_args(arg, str);
     578             :                         } ZEND_HASH_FOREACH_END();
     579             : 
     580         384 :                         if (last_len != str->s->len) {
     581         226 :                                 str->s->len -= 2; /* remove last ', ' */
     582             :                         }
     583             :                 } else {
     584           1 :                         zend_error(E_WARNING, "args element is no array");
     585             :                 }
     586             :         }
     587             :         smart_str_appends(str, ")\n");
     588         390 : }
     589             : /* }}} */
     590             : 
     591             : /* {{{ proto string Exception|Error::getTraceAsString()
     592             :    Obtain the backtrace for the exception as a string (instead of an array) */
     593         524 : ZEND_METHOD(exception, getTraceAsString)
     594             : {
     595             :         zval *trace, *frame, rv;
     596             :         zend_ulong index;
     597             :         zval *object;
     598             :         zend_class_entry *base_ce;
     599         524 :         smart_str str = {0};
     600         524 :         uint32_t num = 0;
     601             : 
     602         524 :         DEFAULT_0_PARAMS;
     603             :         
     604         523 :         object = getThis();
     605         523 :         base_ce = zend_get_exception_base(object);
     606             : 
     607         523 :         trace = zend_read_property(base_ce, object, "trace", sizeof("trace")-1, 1, &rv);
     608         523 :         if (Z_TYPE_P(trace) != IS_ARRAY) {
     609           1 :                 RETURN_FALSE;
     610             :         }
     611        1304 :         ZEND_HASH_FOREACH_NUM_KEY_VAL(Z_ARRVAL_P(trace), index, frame) {
     612         391 :                 if (Z_TYPE_P(frame) != IS_ARRAY) {
     613           1 :                         zend_error(E_WARNING, "Expected array for frame %pu", index);
     614           1 :                         continue;
     615             :                 }
     616             : 
     617         390 :                 _build_trace_string(&str, Z_ARRVAL_P(frame), num++);
     618             :         } ZEND_HASH_FOREACH_END();
     619             : 
     620             :         smart_str_appendc(&str, '#');
     621         522 :         smart_str_append_long(&str, num);
     622             :         smart_str_appends(&str, " {main}");
     623             :         smart_str_0(&str);
     624             : 
     625         522 :         RETURN_NEW_STR(str.s);
     626             : }
     627             : /* }}} */
     628             : 
     629             : /* {{{ proto Throwable Exception|Error::getPrevious()
     630             :    Return previous Throwable or NULL. */
     631          11 : ZEND_METHOD(exception, getPrevious)
     632             : {
     633             :         zval rv;
     634             : 
     635          11 :         DEFAULT_0_PARAMS;
     636             : 
     637          11 :         ZVAL_COPY(return_value, GET_PROPERTY_SILENT(getThis(), "previous"));
     638             : } /* }}} */
     639             : 
     640        2871 : size_t zend_spprintf(char **message, size_t max_len, const char *format, ...) /* {{{ */
     641             : {
     642             :         va_list arg;
     643             :         size_t len;
     644             : 
     645        2871 :         va_start(arg, format);
     646        2871 :         len = zend_vspprintf(message, max_len, format, arg);
     647        2871 :         va_end(arg);
     648        2871 :         return len;
     649             : }
     650             : /* }}} */
     651             : 
     652        8465 : zend_string *zend_strpprintf(size_t max_len, const char *format, ...) /* {{{ */
     653             : {
     654             :         va_list arg;
     655             :         zend_string *str;
     656             : 
     657        8465 :         va_start(arg, format);
     658        8465 :         str = zend_vstrpprintf(max_len, format, arg);
     659        8465 :         va_end(arg);
     660        8465 :         return str;
     661             : }
     662             : /* }}} */
     663             : 
     664             : /* {{{ proto string Exception|Error::__toString()
     665             :    Obtain the string representation of the Exception object */
     666         506 : ZEND_METHOD(exception, __toString)
     667             : {
     668             :         zval trace, *exception;
     669             :         zend_class_entry *base_ce;
     670             :         zend_string *str;
     671             :         zend_fcall_info fci;
     672             :         zval fname, rv;
     673             : 
     674         506 :         DEFAULT_0_PARAMS;
     675             : 
     676         505 :         str = STR_EMPTY_ALLOC();
     677             : 
     678         505 :         exception = getThis();
     679        1010 :         ZVAL_STRINGL(&fname, "gettraceasstring", sizeof("gettraceasstring")-1);
     680             : 
     681        2547 :         while (exception && Z_TYPE_P(exception) == IS_OBJECT) {
     682         517 :                 zend_string *prev_str = str;
     683        1033 :                 zend_string *message = zval_get_string(GET_PROPERTY(exception, "message"));
     684        1032 :                 zend_string *file = zval_get_string(GET_PROPERTY(exception, "file"));
     685        1032 :                 zend_long line = zval_get_long(GET_PROPERTY(exception, "line"));
     686             : 
     687         516 :                 fci.size = sizeof(fci);
     688         516 :                 fci.function_table = &Z_OBJCE_P(exception)->function_table;
     689         516 :                 ZVAL_COPY_VALUE(&fci.function_name, &fname);
     690         516 :                 fci.symbol_table = NULL;
     691         516 :                 fci.object = Z_OBJ_P(exception);
     692         516 :                 fci.retval = &trace;
     693         516 :                 fci.param_count = 0;
     694         516 :                 fci.params = NULL;
     695         516 :                 fci.no_separation = 1;
     696             : 
     697         516 :                 zend_call_function(&fci, NULL);
     698             : 
     699         516 :                 if (Z_TYPE(trace) != IS_STRING) {
     700           1 :                         zval_ptr_dtor(&trace);
     701           1 :                         ZVAL_UNDEF(&trace);
     702             :                 }
     703             : 
     704         516 :                 if (Z_OBJCE_P(exception) == type_error_ce && strstr(message->val, ", called in ")) {
     705          25 :                         zend_string *real_message = zend_strpprintf(0, "%s and defined", message->val);
     706             :                         zend_string_release(message);
     707          25 :                         message = real_message;
     708             :                 }
     709             : 
     710         516 :                 if (message->len > 0) {
     711        2910 :                         str = zend_strpprintf(0, "%s: %s in %s:" ZEND_LONG_FMT
     712             :                                         "\nStack trace:\n%s%s%s",
     713         485 :                                         Z_OBJCE_P(exception)->name->val, message->val, file->val, line,
     714         970 :                                         (Z_TYPE(trace) == IS_STRING && Z_STRLEN(trace)) ? Z_STRVAL(trace) : "#0 {main}\n",
     715         485 :                                         prev_str->len ? "\n\nNext " : "", prev_str->val);
     716             :                 } else {
     717         184 :                         str = zend_strpprintf(0, "%s in %s:" ZEND_LONG_FMT
     718             :                                         "\nStack trace:\n%s%s%s",
     719          31 :                                         Z_OBJCE_P(exception)->name->val, file->val, line,
     720          60 :                                         (Z_TYPE(trace) == IS_STRING && Z_STRLEN(trace)) ? Z_STRVAL(trace) : "#0 {main}\n",
     721          31 :                                         prev_str->len ? "\n\nNext " : "", prev_str->val);
     722             :                 }
     723             : 
     724             :                 zend_string_release(prev_str);
     725             :                 zend_string_release(message);
     726             :                 zend_string_release(file);
     727         516 :                 zval_ptr_dtor(&trace);
     728             : 
     729         516 :                 exception = GET_PROPERTY(exception, "previous");
     730             :         }
     731             :         zval_dtor(&fname);
     732             : 
     733         504 :         exception = getThis();
     734         504 :         base_ce = zend_get_exception_base(exception);
     735             : 
     736             :         /* We store the result in the private property string so we can access
     737             :          * the result in uncaught exception handlers without memleaks. */
     738         504 :         zend_update_property_str(base_ce, exception, "string", sizeof("string")-1, str);
     739             : 
     740         504 :         RETURN_STR(str);
     741             : }
     742             : /* }}} */
     743             : 
     744             : /** {{{ Throwable method definition */
     745             : const zend_function_entry zend_funcs_throwable[] = {
     746             :         ZEND_ABSTRACT_ME(throwable, getMessage,       NULL)
     747             :         ZEND_ABSTRACT_ME(throwable, getCode,          NULL)
     748             :         ZEND_ABSTRACT_ME(throwable, getFile,          NULL)
     749             :         ZEND_ABSTRACT_ME(throwable, getLine,          NULL)
     750             :         ZEND_ABSTRACT_ME(throwable, getTrace,         NULL)
     751             :         ZEND_ABSTRACT_ME(throwable, getPrevious,      NULL)
     752             :         ZEND_ABSTRACT_ME(throwable, getTraceAsString, NULL)
     753             :         ZEND_ABSTRACT_ME(throwable, __toString,       NULL)
     754             :         ZEND_FE_END
     755             : };
     756             : /* }}} */
     757             : 
     758             : /* {{{ internal structs */
     759             : /* All functions that may be used in uncaught exception handlers must be final
     760             :  * and must not throw exceptions. Otherwise we would need a facility to handle
     761             :  * such exceptions in that handler.
     762             :  * Also all getXY() methods are final because thy serve as read only access to
     763             :  * their corresponding properties, no more, no less. If after all you need to
     764             :  * override somthing then it is method __toString().
     765             :  * And never try to change the state of exceptions and never implement anything
     766             :  * that gives the user anything to accomplish this.
     767             :  */
     768             : ZEND_BEGIN_ARG_INFO_EX(arginfo_exception___construct, 0, 0, 0)
     769             :         ZEND_ARG_INFO(0, message)
     770             :         ZEND_ARG_INFO(0, code)
     771             :         ZEND_ARG_INFO(0, previous)
     772             : ZEND_END_ARG_INFO()
     773             : 
     774             : static const zend_function_entry default_exception_functions[] = {
     775             :         ZEND_ME(exception, __clone, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
     776             :         ZEND_ME(exception, __construct, arginfo_exception___construct, ZEND_ACC_PUBLIC)
     777             :         ZEND_ME(exception, getMessage, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
     778             :         ZEND_ME(exception, getCode, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
     779             :         ZEND_ME(exception, getFile, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
     780             :         ZEND_ME(exception, getLine, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
     781             :         ZEND_ME(exception, getTrace, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
     782             :         ZEND_ME(exception, getPrevious, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
     783             :         ZEND_ME(exception, getTraceAsString, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
     784             :         ZEND_ME(exception, __toString, NULL, 0)
     785             :         ZEND_FE_END
     786             : };
     787             : 
     788             : ZEND_BEGIN_ARG_INFO_EX(arginfo_error_exception___construct, 0, 0, 0)
     789             :         ZEND_ARG_INFO(0, message)
     790             :         ZEND_ARG_INFO(0, code)
     791             :         ZEND_ARG_INFO(0, severity)
     792             :         ZEND_ARG_INFO(0, filename)
     793             :         ZEND_ARG_INFO(0, lineno)
     794             :         ZEND_ARG_INFO(0, previous)
     795             : ZEND_END_ARG_INFO()
     796             : 
     797             : static const zend_function_entry error_exception_functions[] = {
     798             :         ZEND_ME(error_exception, __construct, arginfo_error_exception___construct, ZEND_ACC_PUBLIC)
     799             :         ZEND_ME(error_exception, getSeverity, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
     800             :         ZEND_FE_END
     801             : };
     802             : /* }}} */
     803             : 
     804       21049 : void zend_register_default_exception(void) /* {{{ */
     805             : {
     806             :         zend_class_entry ce;
     807             :         
     808       21049 :         REGISTER_MAGIC_INTERFACE(throwable, Throwable);
     809             : 
     810       21049 :         memcpy(&default_exception_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
     811       21049 :         default_exception_handlers.clone_obj = NULL;
     812             : 
     813       21049 :         INIT_CLASS_ENTRY(ce, "Exception", default_exception_functions);
     814       21049 :         default_exception_ce = zend_register_internal_class_ex(&ce, NULL);
     815       21049 :         default_exception_ce->create_object = zend_default_exception_new;
     816       21049 :         zend_class_implements(default_exception_ce, 1, zend_ce_throwable);
     817             : 
     818       21049 :         zend_declare_property_string(default_exception_ce, "message", sizeof("message")-1, "", ZEND_ACC_PROTECTED);
     819       21049 :         zend_declare_property_string(default_exception_ce, "string", sizeof("string")-1, "", ZEND_ACC_PRIVATE);
     820       21049 :         zend_declare_property_long(default_exception_ce, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED);
     821       21049 :         zend_declare_property_null(default_exception_ce, "file", sizeof("file")-1, ZEND_ACC_PROTECTED);
     822       21049 :         zend_declare_property_null(default_exception_ce, "line", sizeof("line")-1, ZEND_ACC_PROTECTED);
     823       21049 :         zend_declare_property_null(default_exception_ce, "trace", sizeof("trace")-1, ZEND_ACC_PRIVATE);
     824       21049 :         zend_declare_property_null(default_exception_ce, "previous", sizeof("previous")-1, ZEND_ACC_PRIVATE);       
     825             : 
     826       21049 :         INIT_CLASS_ENTRY(ce, "ErrorException", error_exception_functions);
     827       21049 :         error_exception_ce = zend_register_internal_class_ex(&ce, default_exception_ce);
     828       21049 :         error_exception_ce->create_object = zend_error_exception_new;
     829       21049 :         zend_declare_property_long(error_exception_ce, "severity", sizeof("severity")-1, E_ERROR, ZEND_ACC_PROTECTED);
     830             : 
     831       21049 :         INIT_CLASS_ENTRY(ce, "Error", default_exception_functions);
     832       21049 :         error_ce = zend_register_internal_class_ex(&ce, NULL);
     833       21049 :         error_ce->create_object = zend_default_exception_new;
     834       21049 :         zend_class_implements(error_ce, 1, zend_ce_throwable);
     835             : 
     836       21049 :         zend_declare_property_string(error_ce, "message", sizeof("message")-1, "", ZEND_ACC_PROTECTED);
     837       21049 :         zend_declare_property_string(error_ce, "string", sizeof("string")-1, "", ZEND_ACC_PRIVATE);
     838       21049 :         zend_declare_property_long(error_ce, "code", sizeof("code")-1, 0, ZEND_ACC_PROTECTED);
     839       21049 :         zend_declare_property_null(error_ce, "file", sizeof("file")-1, ZEND_ACC_PROTECTED);
     840       21049 :         zend_declare_property_null(error_ce, "line", sizeof("line")-1, ZEND_ACC_PROTECTED);
     841       21049 :         zend_declare_property_null(error_ce, "trace", sizeof("trace")-1, ZEND_ACC_PRIVATE);
     842       21049 :         zend_declare_property_null(error_ce, "previous", sizeof("previous")-1, ZEND_ACC_PRIVATE);   
     843             : 
     844       21049 :         INIT_CLASS_ENTRY(ce, "ParseError", NULL);
     845       21049 :         parse_error_ce = zend_register_internal_class_ex(&ce, error_ce);
     846       21049 :         parse_error_ce->create_object = zend_default_exception_new;
     847             : 
     848       21049 :         INIT_CLASS_ENTRY(ce, "TypeError", NULL);
     849       21049 :         type_error_ce = zend_register_internal_class_ex(&ce, error_ce);
     850       21049 :         type_error_ce->create_object = zend_default_exception_new;
     851       21049 : }
     852             : /* }}} */
     853             : 
     854      168885 : ZEND_API zend_class_entry *zend_exception_get_default(void) /* {{{ */
     855             : {
     856      168885 :         return default_exception_ce;
     857             : }
     858             : /* }}} */
     859             : 
     860           0 : ZEND_API zend_class_entry *zend_get_error_exception(void) /* {{{ */
     861             : {
     862           0 :         return error_exception_ce;
     863             : }
     864             : /* }}} */
     865             : 
     866       21354 : ZEND_API zend_class_entry *zend_get_error(void) /* {{{ */
     867             : {
     868       21354 :         return error_ce;
     869             : }
     870             : /* }}} */
     871             : 
     872          59 : ZEND_API zend_class_entry *zend_get_parse_error(void) /* {{{ */
     873             : {
     874          59 :         return parse_error_ce;
     875             : }
     876             : /* }}} */
     877             : 
     878         493 : ZEND_API zend_class_entry *zend_get_type_error(void) /* {{{ */
     879             : {
     880         493 :         return type_error_ce;
     881             : }
     882             : /* }}} */
     883             : 
     884             : 
     885        2024 : ZEND_API zend_object *zend_throw_exception(zend_class_entry *exception_ce, const char *message, zend_long code) /* {{{ */
     886             : {
     887             :         zval ex;
     888             : 
     889        2024 :         if (exception_ce) {
     890        1634 :                 if (!instanceof_function(exception_ce, zend_ce_throwable)) {
     891           0 :                         zend_error(E_NOTICE, "Exceptions must implement Throwable");
     892           0 :                         exception_ce = default_exception_ce;
     893             :                 }
     894             :         } else {
     895         390 :                 exception_ce = default_exception_ce;
     896             :         }
     897        2024 :         object_init_ex(&ex, exception_ce);
     898             : 
     899             : 
     900        2024 :         if (message) {
     901        2024 :                 zend_update_property_string(exception_ce, &ex, "message", sizeof("message")-1, message);
     902             :         }
     903        2024 :         if (code) {
     904         944 :                 zend_update_property_long(exception_ce, &ex, "code", sizeof("code")-1, code);
     905             :         }
     906             : 
     907        2024 :         zend_throw_exception_internal(&ex);
     908        2024 :         return Z_OBJ(ex);
     909             : }
     910             : /* }}} */
     911             : 
     912         902 : ZEND_API zend_object *zend_throw_exception_ex(zend_class_entry *exception_ce, zend_long code, const char *format, ...) /* {{{ */
     913             : {
     914             :         va_list arg;
     915             :         char *message;
     916             :         zend_object *obj;
     917             : 
     918         902 :         va_start(arg, format);
     919         902 :         zend_vspprintf(&message, 0, format, arg);
     920         902 :         va_end(arg);
     921         902 :         obj = zend_throw_exception(exception_ce, message, code);
     922         902 :         efree(message);
     923         902 :         return obj;
     924             : }
     925             : /* }}} */
     926             : 
     927          82 : ZEND_API zend_object *zend_throw_error_exception(zend_class_entry *exception_ce, const char *message, zend_long code, int severity) /* {{{ */
     928             : {
     929             :         zval ex;
     930          82 :         zend_object *obj = zend_throw_exception(exception_ce, message, code);
     931          82 :         ZVAL_OBJ(&ex, obj);
     932          82 :         zend_update_property_long(error_exception_ce, &ex, "severity", sizeof("severity")-1, severity);
     933          82 :         return obj;
     934             : }
     935             : /* }}} */
     936             : 
     937         463 : static void zend_error_va(int type, const char *file, uint lineno, const char *format, ...) /* {{{ */
     938             : {
     939             :         va_list args;
     940             : 
     941         463 :         va_start(args, format);
     942         463 :         zend_error_cb(type, file, lineno, format, args);
     943           3 :         va_end(args);
     944           3 : }
     945             : /* }}} */
     946             : 
     947          46 : static void zend_error_helper(int type, const char *filename, const uint lineno, const char *format, ...)
     948             : {
     949             :         va_list va;
     950             : 
     951          46 :         va_start(va, format);
     952          46 :         zend_error_cb(type, filename, lineno, format, va);
     953          45 :         va_end(va);
     954          45 : }
     955             : 
     956             : /* This function doesn't return if it uses E_ERROR */
     957         510 : ZEND_API void zend_exception_error(zend_object *ex, int severity) /* {{{ */
     958             : {
     959             :         zval exception, rv;
     960             :         zend_class_entry *ce_exception;
     961             : 
     962         510 :         ZVAL_OBJ(&exception, ex);
     963         510 :         ce_exception = Z_OBJCE(exception);
     964         510 :         EG(exception) = NULL;
     965         510 :         if (ce_exception == parse_error_ce) {
     966          92 :                 zend_string *message = zval_get_string(GET_PROPERTY(&exception, "message"));
     967          92 :                 zend_string *file = zval_get_string(GET_PROPERTY_SILENT(&exception, "file"));
     968          92 :                 zend_long line = zval_get_long(GET_PROPERTY_SILENT(&exception, "line"));
     969          92 :                 zend_long code = zval_get_long(GET_PROPERTY_SILENT(&exception, "code"));
     970             : 
     971          46 :                 zend_error_helper(code? code : E_ERROR, file->val, line, "%s", message->val);
     972             : 
     973             :                 zend_string_release(file);
     974             :                 zend_string_release(message);
     975         464 :         } else if (instanceof_function(ce_exception, zend_ce_throwable)) {
     976             :                 zval tmp, rv;
     977         464 :                 zend_string *str, *file = NULL;
     978         464 :                 zend_long line = 0;
     979             : 
     980         464 :                 zend_call_method_with_0_params(&exception, ce_exception, NULL, "__tostring", &tmp);
     981         463 :                 if (!EG(exception)) {
     982         463 :                         if (Z_TYPE(tmp) != IS_STRING) {
     983           0 :                                 zend_error(E_WARNING, "%s::__toString() must return a string", ce_exception->name->val);
     984             :                         } else {
     985         463 :                                 zend_update_property_string(zend_get_exception_base(&exception), &exception, "string", sizeof("string")-1, EG(exception) ? ce_exception->name->val : Z_STRVAL(tmp));
     986             :                         }
     987             :                 }
     988         463 :                 zval_ptr_dtor(&tmp);
     989             : 
     990         463 :                 if (EG(exception)) {
     991             :                         zval zv;
     992             : 
     993           0 :                         ZVAL_OBJ(&zv, EG(exception));
     994             :                         /* do the best we can to inform about the inner exception */
     995           0 :                         if (instanceof_function(ce_exception, default_exception_ce) || instanceof_function(ce_exception, error_ce)) {
     996           0 :                                 file = zval_get_string(GET_PROPERTY_SILENT(&zv, "file"));
     997           0 :                                 line = zval_get_long(GET_PROPERTY_SILENT(&zv, "line"));
     998             :                         }
     999             : 
    1000           0 :                         zend_error_va(E_WARNING, (file && file->len > 0) ? file->val : NULL, line,
    1001             :                                 "Uncaught %s in exception handling during call to %s::__tostring()",
    1002           0 :                                 Z_OBJCE(zv)->name->val, ce_exception->name->val);
    1003             : 
    1004           0 :                         if (file) {
    1005             :                                 zend_string_release(file);
    1006             :                         }
    1007             :                 }
    1008             : 
    1009         926 :                 str = zval_get_string(GET_PROPERTY_SILENT(&exception, "string"));
    1010         926 :                 file = zval_get_string(GET_PROPERTY_SILENT(&exception, "file"));
    1011         926 :                 line = zval_get_long(GET_PROPERTY_SILENT(&exception, "line"));
    1012             : 
    1013         463 :                 zend_error_va(severity, (file && file->len > 0) ? file->val : NULL, line,
    1014             :                         "Uncaught %s\n  thrown", str->val);
    1015             : 
    1016             :                 zend_string_release(str);
    1017             :                 zend_string_release(file);
    1018             :         } else {
    1019           0 :                 zend_error(severity, "Uncaught exception '%s'", ce_exception->name->val);
    1020             :         }
    1021             : 
    1022             :         OBJ_RELEASE(ex);
    1023          48 : }
    1024             : /* }}} */
    1025             : 
    1026         445 : ZEND_API void zend_throw_exception_object(zval *exception) /* {{{ */
    1027             : {
    1028             :         zend_class_entry *exception_ce;
    1029             : 
    1030         890 :         if (exception == NULL || Z_TYPE_P(exception) != IS_OBJECT) {
    1031           0 :                 zend_error_noreturn(E_CORE_ERROR, "Need to supply an object when throwing an exception");
    1032             :         }
    1033             : 
    1034         445 :         exception_ce = Z_OBJCE_P(exception);
    1035             : 
    1036         445 :         if (!exception_ce || !instanceof_function(exception_ce, zend_ce_throwable)) {
    1037           2 :                 zend_error(E_EXCEPTION | E_ERROR, "Cannot throw objects that do not implement Throwable");
    1038           2 :                 return;
    1039             :         }
    1040         443 :         zend_throw_exception_internal(exception);
    1041             : }
    1042             : /* }}} */
    1043             : 
    1044             : /*
    1045             :  * Local variables:
    1046             :  * tab-width: 4
    1047             :  * c-basic-offset: 4
    1048             :  * indent-tabs-mode: t
    1049             :  * End:
    1050             :  */

Generated by: LCOV version 1.10

Generated at Sun, 05 Jul 2015 15:44:43 +0000 (13 hours ago)

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