include_stack, function_stack

From: Date: Wed, 30 Aug 2000 23:30:36 +0000
Subject: include_stack, function_stack
Groups: php.dev 
Request: Send a blank email to php-dev+get-31358@lists.php.net to get a copy of this message
Hello, We talked a little bit about a "get_include_history" function that I suggested a couple of days ago. We decided to postpone the debate until release of 4.0.2. Now that it's done, let's open the debate and brainstorm ! :-) As far as debugging/error reporting goes, there are two things that I consider important and usefull when tracking a bug in PHP code (same with others) : 1) include_stack 2) function_call_stack Let's describe how I see them from a user's point of view: 1) get_include_stack() : This function returns an array of arrays : array ( array(1,"test.php"), // primary script that php started with array(23,"class1.inc"), // on line 23 of test.php, class1.inc // was included array(51,"class2.inc") // on line 51 of class1.inc, class2.inc // was included ); Note : The name I gave this at first ("get_include_history") is not appropriate. It would not be an history, but a stack of the current situation. Example : --A.php <?php include ('B.php'); include ('C.php'); ?> -- If an error occurs in C.php, the stack does not say anything about 'B.php' (should it?) I've read some objections to this, requestiong the existence of "hide_include_stack()". I am not 100% against it, but I do not see when it might be usefull. May be an example of attack/behaviour_we_do_not_want would convice me ? 2) function_stack() : The second one is useful in some situations, look : --division.inc <? function division($a,$b) { return $a/$b; } ?> ---main.php <? include('division.inc'); echo division(1,5); echo division(1,"aaa"); echo division(8,0); ?> --- Then, today, you get "division by zero in file 'division.inc' line 2" That does not help, because the problem is not in that function (you could check if $b==0 before doing the divide, but that would not solve the real problem here). The real problem is in main.php, and given this short example it's obvious, but I'm sure all of you have already encountered this kind of situation in a more complex application. If we could get : Error devide by zero function stack : 'division(1,"aaa") on main.php line 3' _That_ would help ! For this one, I do not know if it's OK to let the programmer have access to it. I personnaly think it's not a good idea, so I would rather only add it "inside PHP/Zend", and display it when an error occurs (ie in php_error) I have a lot of other ideas for debugging tools, but let's discuss these ones first. :-) Flavien.

« previous php.dev (#31358) next »