Sledgehammer - A general purpose PHP toolkit


Build Status

A general purpose PHP toolkit, with a focus on debugging.

  • Improved error reporting with Sledgehammer\Core\Debug\ErrorHandler.
  • Improved var_dump() with dump().
  • Improved PDO compatible database connection with Sledgehammer\Core\Database\Connection.



  • Debugging, error-reporting, loggin and profiling functionality.
  • A collection of global functions (that should be included in PHP, imho)
  • Generic utility classes


  • Autoloader : Detects classes and interfaces in any php file and load them when needed. no more includes.
  • ErrorHandler : An error reporting solution.
  • Object : A more strict base class with improved error messages.
  • Dump/dump() : A colorfull var_dump, with copy-pastable array format.
  • Database : PDO Database class enhanced with logging/profiling and improved error/warning detection.
  • Sql : Generating complex queries in a chainable.
  • Collection : Enhanced Array/Iterator handling.
  • Text : Chainable UTF-8 string functions.
  • Url : Read and generate urls in a OOP style.
  • Cache/cache() : Easy caching api using closures.
  • Json : Reliable JSON encoding and decoding.
  • DebugR : Sending debugging information alongside XMLHttpRequests.
  • more...


  • \Sledgehammer\ENVIRONMENT : The current environment ("development", "staging" or "production") based on $_SERVER['APPLICATION_ENV']
  • \Sledgehammer\PATH : The absolute (server)path of the project folder
  • \Sledgehammer\TMP_DIR : The absolute (server)path of the tmp/cache folder


Use composer to install sledgehammer modules.

$ composer.phar require sledgehammer/core:*

Just include('vendor/autoload.php'); and the Sledgehammer Framework (and other installed composer libraries) can be used.

You can try the dump function: dump($var); to check if the installation is successful.


If no \Sledgehammer\ENVIRONMENT constant has been defined, Sledgehammer will look at the value of $_SERVER['APPLICATION_ENV']. If this isn't found either, the default fallback is "production"

You can set the APPLICATION_ENV by adding SetEnv APPLICATION_ENV development to the .htaccess or httpd.conf:

You can force an environment by defining the \Sledgehammer\ENVIRONMENT constant before including "vendor/autoload.php"


Add \Sledgehammer\Core\Debug\ErrorHandler::enable(); to allow the Sledgehammer ErrorHandler to handle the errors, warnings, notices and uncaught exceptions.

The errorhandler sends error reports per email to the address configured in ErrorHandler::instance()->email. By default the emailaddress specified in $_SERVER['SERVER_ADMIN'] is used.

Static files

Serve static files from modules by adding a line to your rewrite/index.php.



The Autoloader Kicks in when the Composer Autoloader was unable to load the class. The Sledgehammer\Core\Autoloader tries to diagnose the issue and loads the class when it can.