Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Exception.php

function PEAR_Exception::toHtml

Generates a HTML representation of the exception

Return value

string HTML code

1 call to PEAR_Exception::toHtml()
PEAR_Exception::__toString in vendor/pear/pear_exception/PEAR/Exception.php
Converts the exception to a string (HTML or plain text)

File

vendor/pear/pear_exception/PEAR/Exception.php, line 376

Class

PEAR_Exception
Base PEAR_Exception Class

Code

public function toHtml() {
    $trace = $this->getTraceSafe();
    $causes = array();
    $this->getCauseMessage($causes);
    $html = '<table style="border: 1px" cellspacing="0">' . "\n";
    foreach ($causes as $i => $cause) {
        $html .= '<tr><td colspan="3" style="background: #ff9999">' . str_repeat('-', $i) . ' <b>' . $cause['class'] . '</b>: ' . htmlspecialchars($cause['message']) . ' in <b>' . $cause['file'] . '</b> ' . 'on line <b>' . $cause['line'] . '</b>' . "</td></tr>\n";
    }
    $html .= '<tr><td colspan="3" style="background-color: #aaaaaa; text-align: center; font-weight: bold;">Exception trace</td></tr>' . "\n" . '<tr><td style="text-align: center; background: #cccccc; width:20px; font-weight: bold;">#</td>' . '<td style="text-align: center; background: #cccccc; font-weight: bold;">Function</td>' . '<td style="text-align: center; background: #cccccc; font-weight: bold;">Location</td></tr>' . "\n";
    foreach ($trace as $k => $v) {
        $html .= '<tr><td style="text-align: center;">' . $k . '</td>' . '<td>';
        if (!empty($v['class'])) {
            $html .= $v['class'] . $v['type'];
        }
        $html .= $v['function'];
        $args = array();
        if (!empty($v['args'])) {
            foreach ($v['args'] as $arg) {
                if (is_null($arg)) {
                    $args[] = 'null';
                }
                else {
                    if (is_array($arg)) {
                        $args[] = 'Array';
                    }
                    else {
                        if (is_object($arg)) {
                            $args[] = 'Object(' . get_class($arg) . ')';
                        }
                        else {
                            if (is_bool($arg)) {
                                $args[] = $arg ? 'true' : 'false';
                            }
                            else {
                                if (is_int($arg) || is_double($arg)) {
                                    $args[] = $arg;
                                }
                                else {
                                    $arg = (string) $arg;
                                    $str = htmlspecialchars(substr($arg, 0, 16));
                                    if (strlen($arg) > 16) {
                                        $str .= '&hellip;';
                                    }
                                    $args[] = "'" . $str . "'";
                                }
                            }
                        }
                    }
                }
            }
        }
        $html .= '(' . implode(', ', $args) . ')' . '</td>' . '<td>' . (isset($v['file']) ? $v['file'] : 'unknown') . ':' . (isset($v['line']) ? $v['line'] : 'unknown') . '</td></tr>' . "\n";
    }
    $html .= '<tr><td style="text-align: center;">' . ($k + 1) . '</td>' . '<td>{main}</td>' . '<td>&nbsp;</td></tr>' . "\n" . '</table>';
    return $html;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal