Barebone\BrowserConsole

The Barebone\BrowserConsole class is a utility wrapper that allows logging information from server-side PHP code directly into the browser's developer console using inline JavaScript output.

  • log(mixed $data): Writes data to console.log().
  • debug(mixed $data): Writes data to console.debug() (hidden by default in some browsers unless "Verbose" level is enabled).
  • error(mixed $data): Writes data to console.error().
  • info(mixed $data): Writes data to console.info().
  • exception(mixed $data): Writes data to console.exception().
  • table(mixed $data): Writes data to console.table().
  • time(): Starts a timer using console.time().
  • timeEnd(): Stops the timer and writes the elapsed time using console.timeEnd().
  • clear(): Clears the console using console.clear().
  • alert(string $data): Triggers a standard client-side browser alert() popup.

Source

<?php
    
    // Logging simple text
    Barebone\BrowserConsole::log("Hello from PHP to Browser Console");
    
    // Logging structured data arrays
    Barebone\BrowserConsole::info([
        "user" => "Frank", 
        "role" => "developer",
        "status" => "active"
    ]);
    
    // Displaying array data as a table in the browser console
    Barebone\BrowserConsole::table([
        ["id" => 1, "name" => "Alice", "email" => "alice@example.com"],
        ["id" => 2, "name" => "Bob", "email" => "bob@example.com"]
    ]);
    
?>
            

Result

Console Output: Open your browser's Developer Tools Console (F12 or Ctrl+Shift+I) to view the live logged entries rendered by the script below.

Class Definition Outline

  • Barebone\BrowserConsole

    Barebone\BrowserConsole
    • [M] write( mixed $data, $where ) : void
    • [M] log( mixed $data ) : void
    • [M] debug( mixed $data ) : void
    • [M] error( mixed $data ) : void
    • [M] info( mixed $data ) : void
    • [M] exception( mixed $data ) : void
    • [M] table( mixed $data ) : void
    • [M] time() : void
    • [M] timeEnd() : void
    • [M] clear() : void
    • [M] alert( string $data ) : void