<?php

class Utility {

  public function __construct() {

    //
  }

  public static function displayError($message) {

    // Clear the buffer.
    ob_end_clean();

    // Terminate with an error message.
    exit("Error: {$message}.");
  }

  public static function getRootAddress() {

    $host = $_SERVER["HTTP_HOST"];

    $protocol;

    if (!empty($_SERVER["HTTP_X_FORWARDED_PROTO"])) {

      $protocol = $_SERVER["HTTP_X_FORWARDED_PROTO"] . "://";
    }
    else {

      if (!empty($_SERVER["HTTPS"])) {

        $protocol = "https://";
      }
      else {

        $protocol = "http://";
      }
    }

    $sub_directory = substr(

      dirname(dirname(__DIR__)),

      strlen($_SERVER["DOCUMENT_ROOT"])
    );

    // Return absolute URL of where Kaku is installed.
    return $protocol . $host . $sub_directory;
  }
}

?>

<?php

if (!defined("KAKU_ACCESS")) {

  // Deny direct access to this file.
  exit();
}

class Utility {

  public function displayError($message) {

    if (ob_get_status()["level"] > 0) {

      // Clear the buffer.
      ob_end_clean();
    }

    // Terminate with an error message.
    exit("Error: {$message}.");
  }
}

?>

Check for buffer before calling ob_end_clean()
Check for buffer before calling ob_end_clean()

If ob_end_clean() is called before ob_start() has been called, PHP will
throw an error. This ensures that the buffer is only terminated if it
exists in the first place.

In addition, getRootAddress() has been removed.
