Tracking the origin of generated code

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
petfel
Forum Newbie
Posts: 1
Joined: Fri Sep 05, 2008 4:44 pm

Tracking the origin of generated code

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Tracking the origin of generated code

Post by Christopher »

(#10850)
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Tracking the origin of generated code

Post 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
User avatar
kaisellgren
DevNet Resident
Posts: 1675
Joined: Sat Jan 07, 2006 5:52 am
Location: Lahti, Finland.

Re: Tracking the origin of generated code

Post by kaisellgren »

WinCacheGrind in the other hand helps you to find speed hogs.
Last edited by kaisellgren on Wed Oct 08, 2008 5:57 am, edited 1 time in total.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Tracking the origin of generated code

Post 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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Tracking the origin of generated code

Post 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 )
Selkirk
Forum Commoner
Posts: 41
Joined: Sat Aug 23, 2003 10:55 am
Location: Michigan

Re: Tracking the origin of generated code

Post 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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Tracking the origin of generated code

Post 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
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Tracking the origin of generated code

Post 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...
Post Reply