Home > Archive > PHP Language > July 2006 > tracing a PHP script
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
tracing a PHP script
|
|
| Swincher 2006-07-06, 6:56 pm |
| Hi, all - --
I an building my first extensive PHP application. As I am doing so, I
have backed myself into a corner where some messed-up logic is
stumping me big-time.
Is there a tool or technique with which I can step through the script
or trace through it so I can see the point at which my logic is
dropping down the hopper?
Many TIA
Ken
| |
|
| "Swincher" <kixjaguar@comcast.net> wrote in message
news:mqsqa2pvtqu3qhgupv55e26nbp4eo15ce8@
4ax.com...
> Is there a tool or technique with which I can step through the script
> or trace through it so I can see the point at which my logic is
> dropping down the hopper?
exit(); // what does not happen?
if(condition) { ... } else { die($variable); } // is $variable right?
if(condition) { die(condition); } // stop, is condition OK?
function($do_stuff) or die($do_stuff . ' went down the hopper.');
If you are getting specific errors you could log them into a database, flat file or what I
like to do sometimes, write it in your markup (hidden from view, unless you use your
browsing client's view source).
Here is an article that might prove more useful.
http://www-128.ibm.com/developerworks/library/os-debug/
In general... are you receiving any errors? What is your code *not* doing? Can you show
us some source so we can have a go at it?
-Lost
| |
|
|
| Centurion 2006-07-07, 3:56 am |
| Swincher wrote:
> Hi, all - --
>
> I an building my first extensive PHP application. As I am doing so, I
> have backed myself into a corner where some messed-up logic is
> stumping me big-time.
>
> Is there a tool or technique with which I can step through the script
> or trace through it so I can see the point at which my logic is
> dropping down the hopper?
>
> Many TIA
>
> Ken
You may want to investigate PHP unit testing. Googling the last three
words of my previous sentence reveals volumes of useful links :)
Cheers,
James
| |
| Swincher 2006-07-07, 6:56 pm |
| On Thu, 6 Jul 2006 20:21:36 -0400, "-Lost"
<spam_ninjaREMOVEME@REMOVEMEcomcast.net> wrote:
>In general... are you receiving any errors? What is your code *not* doing? Can you show
>us some source so we can have a go at it?
Thanks for the links and suggestions. No, I am not receiving errors as
these are logical flaws, not syntax errors. IOW, the program wasn't
doing what I wanted it to do. As it was getting more complex, I wasn't
able to find the flaws.
Yes, those references are past tense: I was able to figure this one
out, but I still will follow your links. It will make the next flaw
easier to diagnose.
Many thanks - - -
Ken
| |
| Swincher 2006-07-07, 6:56 pm |
| On Fri, 07 Jul 2006 15:28:14 +1000, Centurion <spam_this@nowhere.tld>
wrote:
>You may want to investigate PHP unit testing. Googling the last three
>words of my previous sentence reveals volumes of useful links :)
I'll do that. Thank you.
Ken
| |
| kees hessels 2006-07-07, 6:56 pm |
| Ive been using phped from nusphere which works good for me, it does have a
small price tag, but i realy like the editor and debugger..
"Swincher" <kixjaguar@comcast.net> wrote in message
news:mqsqa2pvtqu3qhgupv55e26nbp4eo15ce8@
4ax.com...
> Hi, all - --
>
> I an building my first extensive PHP application. As I am doing so, I
> have backed myself into a corner where some messed-up logic is
> stumping me big-time.
>
> Is there a tool or technique with which I can step through the script
> or trace through it so I can see the point at which my logic is
> dropping down the hopper?
>
> Many TIA
>
> Ken
| |
| IchBin 2006-07-07, 6:56 pm |
| Swincher wrote:
> Hi, all - --
>
> I an building my first extensive PHP application. As I am doing so, I
> have backed myself into a corner where some messed-up logic is
> stumping me big-time.
>
> Is there a tool or technique with which I can step through the script
> or trace through it so I can see the point at which my logic is
> dropping down the hopper?
>
> Many TIA
>
> Ken
You could try PHPEdit
http://www.waterproof.fr/? PHPSESSI...a81c04
ab
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
________________________________________
__________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
| |
|
| It is very difficult correcting logic flow on a complicated app especially if you are using classes
with many functions it's hard to determine where variables are breaking down.
That is why I like to code in a step by step process, at the top of my pages and use a series of
includes. When doing something complex I stop the code flow with
echo "$vaiable1 $variable2";
exit;
and see am i getting the correct results here...
then I comment it out //
and do the same to the next section and so on. Only then when I know the logic is correct I will
then pull out code turn it into functions or parse it out to includes.
If using classes and functions. You will have to carefully test each function. extract/copy it out
and paste to test.php and rigorously test the function, try to break it, pass zeros, or null or '
and see what the results are.
if expecting arrays use print_r($arrayName); it will print out the array values.
It's a major pass in balls to track this shit down, must break it down to smallest components.
I recently downloaded an authorize.net php class from merchantplus.com by the way it's free and a
good study example. Anyway they class is way over the top and added tons of extra shit we didn't
need and in addition the validation logic was not working correctly. I spent an entire day trying to
figure out why - then said fart on it and wrote my own authorize.net script.
Anyway guess i'm going off on a tangent. Another trick I use is to insert javascript popups inside
php code and place it various spots to see are the vaiable being passed correct.
echo "<script language='javascript'> alert('$someVar');</script> ";
On Thu, 06 Jul 2006 15:35:49 -0500, Swincher <kixjaguar@comcast.net> wrote:
>Hi, all - --
>
>I an building my first extensive PHP application. As I am doing so, I
>have backed myself into a corner where some messed-up logic is
>stumping me big-time.
>
>Is there a tool or technique with which I can step through the script
>or trace through it so I can see the point at which my logic is
>dropping down the hopper?
>
>Many TIA
>
>Ken
| |
| Stan McCann 2006-07-08, 6:56 pm |
| Gleep <Gleep@Gleep.com> wrote in
news:d7aua2tote2dfr9d6mlo2af00513rfq2cq@
4ax.com:
> It is very difficult correcting logic flow on a complicated app
> especially if you are using classes with many functions it's hard to
> determine where variables are breaking down.
>
> That is why I like to code in a step by step process, at the top of
> my pages and use a series of includes. When doing something complex
> I stop the code flow with echo "$vaiable1 $variable2";
> exit;
> and see am i getting the correct results here...
> then I comment it out //
I enclose my debugging echo or print_r statements in if($debug) {}. At
the top of each section I'm working with is $debug=. Change 1 to 0
after testing and then change back to 1 if need be. Of course, this
does add extra processing so I remove them all when the entire app is
finished while saving a copy with the debugging info in order to update
the app.
--
Stan McCann, "Uncle Pirate" http://stanmccann.us/
Implementing negative score for googlegroup postings, see
http://blinkynet.net/comp/uip5.html
A zest for living must include a willingness to die. - R.A. Heinlein
| |
|
| Swincher wrote:
> Hi, all - --
>
> I an building my first extensive PHP application. As I am doing so, I
> have backed myself into a corner where some messed-up logic is
> stumping me big-time.
>
> Is there a tool or technique with which I can step through the script
> or trace through it so I can see the point at which my logic is
> dropping down the hopper?
I normally work with a lot of userdefined functions & classes. In the
development fase, I often do this:
$flow = array();
And in functions:
global $flow;
$flow[] = debug_backtrace();
Which will give you method / function, class, line, filename & arguments
used.
print_r($flow); will give me the total flow until that point.
You could print_r(array_slice($flow,-15)) to get only the last 15 statements
to avoid huge amounts of OK code to read through.
Grtz,
--
Rik Wasmus
| |
|
| This is an excellent idea. Never thought about it before.
I found this article about tracing constants and there is a very usefull user comment.
http://www.phpit.net/article/using-globals-php/
"...Why not just use Constants instead? There also various ways to register certain globals and
constants to, I use:
$GLOBALS['constants'][] array('function' => '', 'file' => '', 'line' => '', 'name' =>'' );
I can iterate over this array and find out where I place what, when, where and why, plus I could
extend the array with anything I want, even if I want, wrap it in a function:
function register_constant($array_constant) {
}
I’m using techniques such as this and others on my site and in its various applications. . ..."
On Sat, 8 Jul 2006 20:13:05 +0200, "Rik" <luiheidsgoeroe@hotmail.com> wrote:
>Swincher wrote:
>
>I normally work with a lot of userdefined functions & classes. In the
>development fase, I often do this:
>
>$flow = array();
>
>And in functions:
>global $flow;
>$flow[] = debug_backtrace();
>
>Which will give you method / function, class, line, filename & arguments
>used.
>print_r($flow); will give me the total flow until that point.
>
>You could print_r(array_slice($flow,-15)) to get only the last 15 statements
>to avoid huge amounts of OK code to read through.
>
>Grtz,
| |
| Colin McKinnon 2006-07-16, 6:56 pm |
| Rik wrote:
> Swincher wrote:
>
> I normally work with a lot of userdefined functions & classes. In the
> development fase, I often do this:
>
> $flow = array();
>
> And in functions:
> global $flow;
> $flow[] = debug_backtrace();
>
> Which will give you method / function, class, line, filename & arguments
> used.
Me too - but I go further and put lots of other things in there as well -
like every SQL statement and the GPC vars, sometimes the session vars.
Because each instance of PHP is relatively shortlived you can afford to be
quite profligate - and of course, the advantage of this approach vs.
running in trace mode within an IDE is all the instrumentation is still
there when the code goes into production.
Other useful things to use in conjunction are:
register_tick_function()
register_shutdown_function()
mail() - for delivering the log without scrambling the screen
microtime()
C.
|
|
|
|
|