Hello,

Ok so I'm trying to write an error reporting class and I'm just sort of
experimenting at this point (comments outside the scope of this email
are welcome btw) with how to best implement it. One idea I had (which
isn't working out as well as I'd hoped thus far) is to create an
instance of my error class (incidentally called 'Error') at the start of
each page and then reference that instance from within all other objects
and functions.

Maybe this would be best explained with some code:

<?php

        $e = new Error();

        function my_function()
        {
                // do stuff
                if($this == $that)
                {
                        $e->RaiseError();
                }
        }

?>

Of course, that doesn't work because my_function() doesn't know anything
about $e unless I put a special statement into my_function().

<?php

        function my_function()
        {
                // here's the new line
                global $e;

                // do stuff
                ...
        }

?>

I already don't like the idea of having to put 'global $e;' within each
and every function/method I write. Should I abandon this idea and try
something else? If so, what?

Here is my first idea just fyi.

<?php

        function my_function()
        {
                $e = new Error();

                // do stuff
                if($this == $that)
                {
                        $e->RaiseError();
                }
                else
                {
                        // continue like normal
                }

                // get ready to return a response
                if($e->error_count > 0)
                {
                        return $e;
                }
                else
                {
                        // return something else
                }
        }

?>

Now to use my_function() within a page I have to always assign the
result to a variable so that I can determine whether or not any errors
occured within the function.

<?php

        $result = my_function();

        if($result->error_count > 0)
        {
                // an error occurred
                $result->DisplayErrors();
        }

?>

But that also seems like a hassle (but maybe it's a completely necessary
hassle?). I've looked around the internets for a while but have not
found any REALLY useful documents on managing errors (could be that I've
not found the write article yet) and such so any
comments/pointers/links/etc. are very welcome.

What I'd ultimately like to do is be able to return more than just a
true/false from a function regarding it's end state. For example, a
function could fail for multiple reasons and just returning a plain
false for all situations does not suffice.


Thank you for making it this far.
Chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to