Posted in Information Technology, Software Engineering

PHP Cheat Sheet

Basic Debugging

Value Dumping

print_r($someArray);      # Print flat arrays
var_dump($var);           # Nested printing of arbitrary structures

Handling Exceptions

To catch exceptions do

try {
    # do something
} catch(Exception $e) {
    print "$e\n";

As not all of PHP and its libraries do consistenly throw real exceptions you might want to convert runtime errors (that would otherwise terminate the code execution) into catchable exceptions:

set_error_handler(function($errno, $errstr, $errfile, $errline ){
    throw new ErrorException($errstr, $errno, 0, $errfile, $errline);

Regular Expressings


PHP Security and Hardening

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s