[ create a new paste ] login | about

Link: http://codepad.org/slSX3HKd    [ raw code | output | fork ]

PHP, pasted on Nov 28:
<?php

assert_options(ASSERT_ACTIVE,   true);
assert_options(ASSERT_BAIL,     true);
assert_options(ASSERT_WARNING,  true);
assert_options(ASSERT_CALLBACK, array('UseAsserts', 'onAssertFailure'));

class Asserts
{
    public static function absentOrNotNumeric($value)
    {
        return !isset($value) ? true : is_numeric($value);
    }
}

class UseAsserts
{
    private $value;

    public function __construct($value)
    {
        assert("Asserts::absentOrNotNumeric($value)");
        $this->value = $value;
    }

    public static function onAssertFailure($file, $line, $message)
    {
        throw new Exception($message);
    }
}

// This will trigger a warning and stops execution, but Exception is not thrown
$fail = new UseAsserts('Should fail.');


Output:
1
2
3
4
5

Parse error: syntax error, unexpected T_STRING in /t.php(22) : assert code on line 1

Catchable fatal error: assert(): Failure evaluating code: 
Asserts::absentOrNotNumeric(Should fail.) in /t.php on line 22


Create a new paste based on this one


Comments: