PHPainfree2 Docs

$Painfree->debug() - Documentation | PHPainfree2

PHPainfree2 $Painfree->debug()

$Painfree->debug(string $key, mixed $var, bool $abort) : void

$Painfree->debug()

This function is a useful helper function to store various objects and variables into an array for later viewing. This function is often combined with a template like templates/debug.php to view all of the variables, objects, and arrays that have been added to $Painfree via the debug() method.


public function debug($heading,$obj,$abort=false) : void {
	if ( $abort ) {
		die('<pre>' . $heading . ' = ' . print_r($obj,true) . '</pre>');
	}
	$this->__debug[$heading] = print_r($obj,true);
}

Usage

Use this function whenever you want to inspect a variable later in the execution of your application. Or pass in the $abort argument to immediately halt execution and display the variable information passed to this function.

By default, any information passed to $Painfree->debug(); is not displayed anywhere. In most applications, a common pattern is to create a debugging template and only render that template if the user that is viewing the application has administrator or development permissions for your application.

Example View


<?php
	$debug_cnt = 0;
	foreach ( $Painfree->__debug as $heading => $obj_dump ) {
		$debug_cnt = $debug_cnt + 1;
?>
	<div class="card bg-dark border-warning mb-4">
		<div class="card-header bg-danger bg-opacity-10">
			<h4 class="my-2"><?= $debug_cnt; ?>. <?= $heading; ?></h4>
		</div>
		<div class="card-body p-4">
			<pre><code class="language-php"
				><?= $heading; ?> = <?= $obj_dump; ?></code></pre>
		</div>
	</div>
<?php
	}
?>