How to print an error to the console in PHP

PHP
// Assuming you are wishing to log to the JS Console...

<?php
	function consoleLog($msg) {
		echo '<script type="text/javascript">' .
          'console.log(' . $msg . ');</script>';
	}

	consoleLog('Hello, console!');
?><script>
    console.log(<?= json_encode($foo); ?>);
</script>
Source

Also in PHP: