Hey all

I dont think there is a simple way of doing this but i've got a number of different functions, what each call a database function.

So to simplify lets say function a and function b both call function database.

If there is an error in function database, its because the function that called it has caused a problem. Is there a way I can display which function (function a or function b) called function database within the funcion database code?

I realise I've probably overused the word function quite a bit, but its far better than my first draft! 🙂

Thanks

Tim

    I'm sure there is a better way, but, you can have a parameter which allows you to say which function called it, and it will return that on error.

    That or you can just have it echo "Error: function a messed up".

    function c ($params, $refer=null) {
      if ($error) {
       return $refer;
      }
    }
    function a($params) {
     echo "yay";
     c('big.nerd','a');
    }
    function b($params) {
     echo "yay";
     c('big.nerd','b');
    
    }
    

      Hey

      Thanks for the reply, I was trying to avoid the parameter route if possible. I thought that php would have to know where it was returning the result of the function to, so it might store it somewhere, but I the parameter way isn't a bad idea to be going on with

      Many thanks

      Tim

        Tim,

        Keep your eyes open here for a bit more.. if someone knows, they will say it.

          You could receive the results from the database function in function a or b, determine if they are valid and if not

          echo __FILE__.__FUNCTION__.__LINE__; //Run this and look at what it gives you
          

          If you do the param route like above you could generalize it a bit more by doing

          function c ($params, $refer=null) {
            if ($error) {
             return $refer;
            }
          }
          function a($params) {
          echo "yay";
          c('big.nerd',__FUNCTION__);
          }
          function b($params) {
          echo "yay";
          c('big.nerd',__FUNCTION__);
          
          } 
          

          http://phpbuilder.com/manual/en/language.constants.predefined.php

            Now I'm gonna be a smart ass, just warning in advance. But first let me say that I have seen this question a couple of times before here, and noone have managed to say that there are a way to do it other than the above suggested.

            Now for the smart ass part. If the function works it doesn't matter where the data comes from. If it doesn't work it still doesn't matter. There are only two possible things that can be wrong:

            1. Something is wrong in the function. If it is it doesn't matter where the data comes from, what is important is that the function is corrected.

            2. The function is called in a way/with data that it wasn't designed for. It still doesn't matter that you can't see where the call came from, the error is that the function is called at all. I can agree that in this case it would be good to know where the data came from, but it is not essential.

              Hey guys

              Thanks for all the help, it looks like using the constants and parameters combination might be the way to go. I think what Piranha is suggesting is that I need to tighten up on my error checking and I shouldn't be calling this function if the data passed isn't correct?

              I use this function for running queries so it checks the data its sent and reports any errors. As this function can be called many times from the same function and the same script, using the constants might save me a lot of the hard work of trying to discover exactly where the data has come from.

              Shame you can't just do
              function c ($params, $refer=FUNCTION) {
              if ($error) {
              return $refer;
              }

              Thanks again guys, I'll leave this unresolved in case anyone has any feedback

              Tim

                timus wrote:

                I think what Piranha is suggesting is that I need to tighten up on my error checking and I shouldn't be calling this function if the data passed isn't correct?

                Exactly. Of course it is not possible to find every error with a normal error checking, but when an error occurs you should go to the function to find it, not whatever it is that is calling the function.

                  I see what you're saying but surely there is an argument for having the error checking in its own function rather than in every function, in which case it is important to know where that data is coming from. But I agree you're right my checking should be much tighter

                  Many thanks

                    I don't mean error checking in the function itself, wrong word. I mean that you should debug the function and check that it is working as expected. And when you do get an error you should debug the function again to see why you got the error.

                      I think I see what you mean

                      Thanks for the help

                        Write a Reply...