SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 36 of 36
  1. #26
    SitePoint Guru
    Join Date
    May 2005
    Location
    Finland
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sleepeasy
    The only place I've seen error_reporting getting set to 0 documented is here (the last sentence):
    Thanks. I must've misread that back then.

  2. #27
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sleepeasy
    The only place I've seen error_reporting getting set to 0 documented is here (the last sentence):
    This is actually very useful piece of information. I have modified my code accordingly:

    PHP Code:
    function exceptions_error_handler($severity$message$filename$lineno)
    {
        
    $throwable  = array(E_ERROR,
                            
    E_WARNING,
                            
    E_PARSE,
                            
    //E_NOTICE,
                            
    E_CORE_ERROR,
                            
    E_CORE_WARNING,
                            
    E_COMPILE_ERROR,
                            
    E_COMPILE_WARNING,
                            
    E_USER_ERROR,
                            
    E_USER_WARNING,
                            
    E_USER_NOTICE,
                            
    E_ALL,
                            
    //E_STRICT,
                            
    );
        
    //var_dump($severity);
        
    if (ini_get('error_reporting') && in_array($severity$throwable)) {
            throw new 
    ErrorException($message0$severity$filename$lineno);
        }

    Now the next step would be using some kind of bitwise logic to find out if severity is contained within error_reporting, to get rid of the $throwable array whatsoever, but I don't have the time right now to look for it. Anyone?

  3. #28
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BerislavLopac
    This is actually very useful piece of information. I have modified my code accordingly:

    PHP Code:
    function exceptions_error_handler($severity$message$filename$lineno)
    {
        
    $throwable  = array(E_ERROR,
                            
    E_WARNING,
                            
    E_PARSE,
                            
    //E_NOTICE,
                            
    E_CORE_ERROR,
                            
    E_CORE_WARNING,
                            
    E_COMPILE_ERROR,
                            
    E_COMPILE_WARNING,
                            
    E_USER_ERROR,
                            
    E_USER_WARNING,
                            
    E_USER_NOTICE,
                            
    E_ALL,
                            
    //E_STRICT,
                            
    );
        
    //var_dump($severity);
        
    if (ini_get('error_reporting') && in_array($severity$throwable)) {
            throw new 
    ErrorException($message0$severity$filename$lineno);
        }

    Now the next step would be using some kind of bitwise logic to find out if severity is contained within error_reporting, to get rid of the $throwable array whatsoever, but I don't have the time right now to look for it. Anyone?
    As I posted previously..

    PHP Code:
    function errorToExceptionHandler($severity$message$file$line

        if (
    error_reporting() & $severity
            throw new 
    ErrorException($message0$severity$file$line); 

    Which allows using error_reporting() to set which E_* severities cause an exception, and if @ is used and error_reporting() is zero, so the condition still fails.

  4. #29
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, I just go to that myself later last night, just didn't get around to post it.
    Missed your previous post with it, though...

  5. #30
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, there still seems some issues with throwing exceptions on E_* errors. The exception getTrace() returns the errorToExceptionHandler function name. And no proper way to correct this. Other than if ($exception instanceof ErrorException) { .. fixup .. }.

  6. #31
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, it would be a nice homework for zend devs to write 1000 times: "I will never use privates/finals in core classes".

  7. #32
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stereofrog
    Yeah, it would be a nice homework for zend devs to write 1000 times: "I will never use privates/finals in core classes".
    Yes, opened a bug for it anyways.

  8. #33
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hah.

    Bug got marked as bogus, its apparently expected behaviour!?

    http://bugs.php.net/bug.php?id=37224

  9. #34
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ren
    Bug got marked as bogus, its apparently expected behaviour!?
    What did you expect?

    It is expected, as in "it's said so in the manual". A classic example of the "it's not a bug, it's a feature" syndrome that has apparently infested the PHP team recently.

  10. #35
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ren
    Hah.

    Bug got marked as bogus, its apparently expected behaviour!?

    http://bugs.php.net/bug.php?id=37224
    The guy doesn't seem to have bothered to read your post fully... ;(

    The actual problem is that ErrorException modifies trace in an incorrect manner, so that 'args' member is shifted one frame up. This is the specific ErrorExpression problem, shift doesn't occur with ordinary Exception. Illustration:

    PHP Code:
    function errorneous($a$b$c) {
        try { 
    1/0; }
        catch(
    Exception $e) {
            
    $GLOBALS['from_excp'] = $e->getTrace();
        }
    }

    //-----------------------------------------------
    // test with basic Exception

    function _err_to_basic_ex($code$msg$file$line)  {
        
    $GLOBALS['from_backtrace'] = debug_backtrace();
        throw new 
    Exception();
    }

    echo 
    "Exception...\n";
    set_error_handler('_err_to_basic_ex');
    errorneous('args''of''errorneous');

    # with Exception both traces are equal
    var_dump($from_backtrace == $from_excp);

    //-----------------------------------------------
    // test with ErrorException

    function _err_to_error_ex($code$msg$file$line)  {
        
    $GLOBALS['from_backtrace'] = debug_backtrace();
        throw new 
    ErrorException($msg0$code$file$line);
    }

    echo 
    "ErrorException...\n";
    set_error_handler('_err_to_error_ex');
    errorneous('args''of''errorneous');

    # with ErrorException both traces are NOT equal
    # because args are shifted
    var_dump($from_backtrace == $from_excp); 

  11. #36
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, just had an idea

    How about having an exception for asserts() too...

    PHP Code:
    <?php

    class AssertException extends ErrorException
    {
        function 
    __construct($script$line$message)
        {
            
    parent::__construct('Assertion Exception'0E_USER_WARNING$script$line);
        }
    }

    function 
    assertToExceptionHandler($script$line$message )
    {
        throw new 
    AssertException($script$line$message);
    }

    assert_options(ASSERT_ACTIVE1);
    assert_options(ASSERT_WARNING0);
    assert_options(ASSERT_QUIET_EVAL0);
    assert_options(ASSERT_CALLBACK'assertToExceptionHandler');

    function 
    test($a)
    {
        
    assert('$a > 0 && $a < 10');
    }

    test(11);
    Not sure I like it yet.. thou I think thats in part due to the nature of PHPs assert() being eval() like.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •