Page 1 of 1

Tracking the origin of generated code

Posted: Fri Sep 05, 2008 5:10 pm
by petfel
I have come to PHP via open source CMS but I want to understand PHP in more depth. The best way I found so far is tracking the flow of program execution but understanding which php files have contributed code to a finished page is very slow and demanding work. Maybe that's just the way it is for everyone learning? Maybe also there is a faster way like with a 'trace' function of some kind which comments each block of generated code with the name of the contributing module? (I cannot see any reference to such a facility in the PHP ref manual but maybe I look in the wrong place) Do I just keep on doing what I am already doing or is there a more efficient learning pathway?

Re: Tracking the origin of generated code

Posted: Fri Sep 05, 2008 6:27 pm
by Christopher

Re: Tracking the origin of generated code

Posted: Sat Sep 06, 2008 12:00 am
by josh
GUI based debugging to the rescue.

NuSphere's PhpED is pretty nice, doesn't allow you to move backwards in program execution for some reason?

Zend also has the same functionality but I find zend studio to be a pain to use in practice, too many nuisances, phpEd is worth the 250% more in price to me

Re: Tracking the origin of generated code

Posted: Sat Oct 04, 2008 6:35 am
by kaisellgren
WinCacheGrind in the other hand helps you to find speed hogs.

Re: Tracking the origin of generated code

Posted: Sat Oct 04, 2008 1:50 pm
by alex.barylski
Maybe that's just the way it is for everyone learning
Stepping through code is about the only way to learn unless you have superior docs -- which never exist.

Re: Tracking the origin of generated code

Posted: Sat Oct 04, 2008 2:55 pm
by josh
With GUI based debugging you don't have to step along thru anything, you can just set breakpoints and run the debugger
also, file find and replace works wonders, any good editor will have a feature for locating files, for instance phpED lets me search within functions, classes, filenames, whatever I want

I find tutorials are docs are the best source of learning, and books too... stepping thru code is usually how I do it though ( which leaves you only half understanding it in most cases )

Re: Tracking the origin of generated code

Posted: Sun Oct 05, 2008 1:14 am
by Selkirk
When I review a new PHP package, I almost always start by dropping this at the bottom of its index.php:

Code: Select all

 
echo implode(get_included_files(), "\n");
 
I also use this also quite a bit in optimizing code. Quite often files will get loaded that aren't even necessary.

Re: Tracking the origin of generated code

Posted: Sun Oct 05, 2008 2:45 am
by josh
haha that reminds me, phpED ( and zend I think ) have a profiler, you can profile a page request and then see not only all the files that were included, which methods & classes were called, how many times each method was called, avg min and max time to execute, and sort on it all. The get included files thing is a great idea I wish I had thought of, before I discovered the magical world of IDEs

Re: Tracking the origin of generated code

Posted: Wed Oct 08, 2008 3:17 am
by alex.barylski

Code: Select all

echo implode(get_included_files(), "\n");
Why didn't I think of that. :(

That's actually a really good idea...