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
	}
?>

PHPainfree Debugging Console [exec: 0.0022s]

1. App

App = App Object
(
    [title:App:private] => Painfree-debug -  Documentation |  PHPainfree2
    [htmx] => 
    [htmx_boosted] => 
    [route] => docs/painfree-debug
    [view] => docs
    [id] => painfree-debug
    [action] => 
    [data] => Array
        (
            [doc] => painfree-debug
        )

    [objects] => Array
        (
        )

    [BASE_PATH] => /var/www/vhosts/php.programming-is-easy.com
)

2. Painfree

Painfree = PHPainfree Object
(
    [Version] => 2.2.1
    [URI] => https://php.programming-is-easy.com/docs/painfree-debug
    [route] => docs/painfree-debug
    [Root] => /var/www/vhosts/php.programming-is-easy.com/
    [db] => 
    [Autoload] => Array
        (
        )

    [__debug] => Array
        (
            [App] => App Object
(
    [title:App:private] => Painfree-debug -  Documentation |  PHPainfree2
    [htmx] => 
    [htmx_boosted] => 
    [route] => docs/painfree-debug
    [view] => docs
    [id] => painfree-debug
    [action] => 
    [data] => Array
        (
            [doc] => painfree-debug
        )

    [objects] => Array
        (
        )

    [BASE_PATH] => /var/www/vhosts/php.programming-is-easy.com
)

        )

    [options:PHPainfree:private] => Array
        (
            [ApplicationController] => App.php
            [BaseView] => app.php
            [DefaultRoute] => main
            [PublicFolder] => htdocs
            [TemplateFolder] => templates
            [LogicFolder] => includes
            [ControllerFolder] => Controllers
            [ImagesFolder] => images
            [CssFolder] => css
            [JsFolder] => js
            [DynamicFolder] => views
            [Database] => Array
                (
                )

            [RouteParameter] => route
        )

)

3. DebugExamples

DebugExamples = Please be aware that there are several $Painfree->debug() calls made in templates/debug.php to be used as examples. You should probably remove them.

4. $TestArray

$TestArray = Array
(
    [this_is] => a simple dummy array.
    [example] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )

)

5. $PainfreeConfig

$PainfreeConfig = Array
(
    [ApplicationController] => App.php
    [BaseView] => app.php
    [DefaultRoute] => main
    [PublicFolder] => htdocs
    [TemplateFolder] => templates
    [LogicFolder] => includes
    [ControllerFolder] => Controllers
    [ImagesFolder] => images
    [CssFolder] => css
    [JsFolder] => js
    [DynamicFolder] => views
    [Database] => Array
        (
        )

    [RouteParameter] => route
)

6. EXAMPLE

EXAMPLE = You can basically pass anything to $Painfree->debug().