Skip to content

Instantly share code, notes, and snippets.

@ssddanbrown
Last active March 3, 2023 03:22
Show Gist options
  • Save ssddanbrown/bdeac0c9409a6d2712e396a0ab6c7de1 to your computer and use it in GitHub Desktop.
Save ssddanbrown/bdeac0c9409a6d2712e396a0ab6c7de1 to your computer and use it in GitHub Desktop.
console.log in PHP
<?php
// Note: The namespace is required since a 'log' function already exists in PHP
// and that can't be overriden without having an extension installed, so we
// use a namespace which allows us to use the function name.
namespace app;
const console = '';
function log(...$args) {
var_dump(...$args);
return '';
}
console.log('thingA', 5, [1,2]);
// Outputs:
// test.php:16:
// string(6) "thingA"
// test.php:16:
// int(5)
// test.php:16:
// array(2) {
// [0] =>
// int(1)
// [1] =>
// int(2)
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment