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.
<?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"]
]);
?>