Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using user_error() issue. 1

Status
Not open for further replies.

thenewa2x

Programmer
Dec 10, 2002
349
US
Here's an example of what I'm using:
Code:
class LIB
{
    function test ( $again = "" )
    {
        if ( !@self::junk( $again ) )
        {
            // Report.
            user_error( "You should have given, \$again!",
                        E_USER_ERROR );
        }

        print( "Hi." );
    }

    function junk ( $var = "" )
    {
        if ( empty( $var ) )
        {
            // Report.
            user_error( "Argument, \$var, is required.",
                        E_USER_ERROR );

            return( false );
        }
    }
}

LIB::test( );

The above is a working example but it is not my original code. It should pump out a user error of "You should have given, $again!" but it doesn't appear to do anything at all.

Is this a bug? If it is, is there a work around?

---------------------------------------
 
what level of error display do you have? it may not be high enough to display user-errors.

to test add the directive
Code:
error_reporting(E_ALL);
to the start of your script.
 
I see. I did what you suggested and the only error I had was a notice of an undefined index which is irrelevant so I couldn't fix anything. Thanks for you suggestion though.

Also, I think you misunderstood what I was trying to accomplish, I'll tweak the code just a bit.

Code:
class LIB
{
    function test ( $again = "" )
    {
        if ( !@self::junk( $again ) )
        {
            print( "Bad mojo." );
        }

        print( "Hi." );
    }

    function junk ( $var = "" )
    {
        if ( empty( $var ) )
        {
            // Report.
            user_error( "Argument, \$var, is required.",
                        E_USER_ERROR );

            return( false );
        }
    }
}

LIB::test( );

It should be printing out "Bad mojo". Instead, it looks like the script dies right there.

---------------------------------------
 
Also, I noticed that the error is submitted to my errors log but not displayed, even though it shouldn't be doing any of that.

---------------------------------------
 
If you remove the error suppressor '@' in this call:
Code:
!@self::junk( $again )
You will receive:
Code:
Fatal error: Undefined class name 'self'
Change 'self' to LIB and the code should perform the way you expect.
 
E_USER_ERROR causes the php error handler to stop further execution. either write your own error handler or put a different error level in (try E_NOTICE).
 
sorry - boo boo there. should be E_USER_NOTICE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top