Skip to content

Instantly share code, notes, and snippets.

@hofmannsven
Last active September 17, 2023 20:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hofmannsven/7613663 to your computer and use it in GitHub Desktop.
Save hofmannsven/7613663 to your computer and use it in GitHub Desktop.
Debugging settings and techniques for PHP
php -i
php -v
php -m
export MAMP_PHP=/Applications/MAMP/bin/php/php5.6.10/bin
export PATH="$MAMP_PHP:$PATH"
<?php
// output value
echo $variable;
// output array
print_r($array); // wrap with <pre> for nice formatting
// output type
echo gettype($variable);
// output type and value
var_dump($variable);
// output vars
print_r(get_defined_vars());
// output backtrace, type and value
function initialize($hello) {
echo $hello . '<br />';
var_dump(debug_backtrace());
}
initialize('Hello World!');
// output all hooks
add_action('all', 'hack_all_hooks');
function hack_all_hooks() {
var_dump( current_filter() );
};
<?php
// display errors
ini_set('display_errors', 'On');
error_reporting(E_ALL);
<?php
function dump($value) {
echo '<pre>';
var_dump($value);
echo '</pre>';
}
<?php
if(!function_exists('_log')){
function _log( $message ) {
if( WP_DEBUG === true ){
if( is_array( $message ) || is_object( $message ) ){
error_log( print_r( $message, true ) );
} else {
error_log( $message );
}
}
}
}
display_errors = On
error_reporting = E_ALL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment