methods of debugging - atomate.net

14
Methods of debugging

Upload: vitalie-chiperi

Post on 24-Jan-2017

199 views

Category:

Technology


1 download

TRANSCRIPT

Methods of debugging

Exceptions

$exception = new Exception("Error message",1);

$exception->getCode();$exception->getMessage();

throw $exception;

Exceptions

• try{throw new Exception('Exception');

} catch (Exception $e){//...

} catch (OutOfBoundsException $e){//...

} finally {// finally only for > PHP 5.5

}

Exception Handlers

set_exception_handler('exception_handler');

function exception_handler(Exception $e){// This method will be called for every uncaught exception}

// Used after changing the exception handler, to revert to the previous onerestore_exception_handler();

Error Handler

set_error_handler(function($errno, $errstr, $errfile, $errline, array $errcontext) { // error

});

PHP INI CONF

DEVELOPMENT

// Display errorsdisplay_startup_errors = Ondisplay_errors = On

//Report all errorserror_reporting = -1

//Turn on error logginglog_errors = On

PRODUCTION// Do not display errorsdisplay_startup_errors = Offdisplay_errors = Off

// Report all errors BUT NO noticeserror_reporting = E_ALL & ~E_NOTICE

//Log Errorslog_errors = On

DEBUGGING TOOLS

var_dump($jsonDecodedObj)

object(stdClass)#117 (1) { ["glossary"]=> object(stdClass)#118 (2) { ["title"]=> string(16) "example glossary" ["GlossDiv"]=> object(stdClass)#119 (2) { ["title"]=> string(1) "S" ["GlossList"]=> object(stdClass)#120 (1) { ["GlossEntry"]=> object(stdClass)#121 (7) { ["ID"]=> string(4) "SGML" ["SortAs"]=> string(4) "SGML" ["GlossTerm"]=> string(36) "Standard Generalized Markup Language" ["Acronym"]=> string(4) "SGML" ["Abbrev"]=> string(13) "ISO 8879:1986" ["GlossDef"]=> object(stdClass)#122 (2) { ["para"]=> string(72) "A meta-markup language, used to create markup languages such as DocBook." ["GlossSeeAlso"]=> array(2) { [0]=> string(3) "GML" [1]=> string(3) "XML" } } ["GlossSee"]=> string(6) "markup" } } } } }

Kint::dump($jsonDecodedObj)

PHP Debug Bar

Laravel Debugbar (Integrates PHP Debug Bar)

XDebug

Rubber duck debugging

• Rubber duck debugging is an informal term used in software engineering for a method of debugging code. The name is a reference to a story in a book in which a programmer would carry around a rubber duck and debug their code by forcing themselves to explain it, line-by-line, to the duck. Many other terms exist for this technique, often involving different inanimate objects.

• Many programmers have had the experience of explaining a programming problem to someone else, possibly even to someone who knows nothing about programming, and then hitting upon the solution in the process of explaining the problem.

source: wikipedia.org