2017 © Pedro Peláez
 

library strictmode-php

image

dan-da/strictmode-php

  • Wednesday, July 18, 2018
  • by danda
  • Repository
  • 1 Watchers
  • 0 Stars
  • 209 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 38 % Grown

The README.md

strictmode-php

A tiny php include to make php code more strict and catch problems sooner., (*1)

This library catches all PHP notices, warnings, and errors and turns them into PHP exceptions., (*2)

It also catches all uncaught exceptions and prints a stack trace. It can also send an email alert for uncaught exceptions., (*3)

The net result is that minor problems are caught early in development and it forces the developer to write much cleaner code., (*4)

The email alerts are useful for production environments, to notify site operators of any problems., (*5)

strictmode.php is a single file that can be included with require_once or can be included via autoload when using composer., (*6)

Let's see an example.

app code:, (*7)

This uses require_once(), see below for autoload example., (*8)

<?php
require_once( __DIR__ . '/../strictmode.php');
define( 'strictmode\ALERTS_MAILTO', 'yourmail@yourdomain.com' );
...

echo HELLO;   // this will generate a PHP notice.

output:, (*9)

Uncaught Exception. code: 8, message: Use of undefined constant HELLO - assumed 'HELLO'
/home/danda/dev/strictmode-php/t.php : 7

Stack Trace:
#0 /home/danda/dev/strictmode-php/t.php(7): strictmode\_global_error_handler(8, 'Use of undefine...', '/home/danda/dev...', 7, Array)
#1 {main}

INFO: alert sent to yourmail@yourdomain.com


Now exiting.  Please report this problem to the software author

For comparison, here is normal php output without strictmode.php, (*10)

PHP Notice:  Use of undefined constant HELLO - assumed 'HELLO' in /home/danda/dev/strictmode-php/t.php on line 7
HELLO

including via composer / autoload

<?php
require_once __DIR__  . '/../vendor/autoload.php';
define( 'strictmode\ALERTS_MAILTO', 'yourmail@yourdomain.com' );
\strictmode\initializer::init();

// your app code...

Configuring email alerts

set alert address

define( 'strictmode\ALERTS_MAILTO', 'yourmail@yourdomain.com' );

disable warning if ALERTS_MAILTO not set

define( 'strictmode\ALERTS_DISABLE', 1 );

Installation and Running.

Install strictmode-php into your own project using a composer require in your project's composer.json, eg:, (*11)

    $ cd yourproject
    $ composer require dan-da/strictmode-php

Then run composer install., (*12)

Todos

  • add more test cases

The Versions

18/07 2018

dev-master

9999999-dev

  Sources   Download

The Requires

 

18/07 2018

v1.0.1

1.0.1.0

  Sources   Download

06/09 2017

v1.0.0

1.0.0.0

  Sources   Download

The Requires