Couldn't you use `%Z` here too?

      len = zend_spprintf(&str, 0, "exception '%s' with message '%Z' in %s:%ld\nStack trace:\n%s%s%s",
                Z_OBJCE_P(exception)->name, &message, Z_STRVAL(file), Z_LVAL(line),
                (trace && Z_STRLEN_P(trace)) ? Z_STRVAL_P(trace) : "#0 {main}\n",
                len ? "\n\nNext " : "", prev_str);