We available for hire! — Need help with a web or mobile project?
From yensdesign we develop technology projects based on web apps, mobile apps, consulting and databases. We are young and hard workers, passionate about innovation and focused in new technologies.If you want to ask for a budget, we hare available for hire!.
Faster and smarter debugging of PHP scripts
June 3rd, 2009Today nobody really questions benefits of using source level debuggers for any language including PHP – debugger is simply a tool, necessity in everyday programmers work. However, it is interesting to note that code validating tools are much less known and it is those tools that are very valuable addition to debuggers in code development.
Traditionally, in compiled languages, certain part of code validation (type checking, checking for non-initialized variables) are usually taken by compiler, but besides compiler there are also external tools used to conduct this task (for example checkstyle for Java). This article deals with use of one of those tools (Codenizer) during development of PHP applications.
Basic question that programmer asks herself/himself when introducing one new tool into development process is “What benefit can I expect from using this?” Answer to this question is very simple – it is dramatic time saver during development, and we all know what that means in today’s world of merciless business competition – more time you save in development of one application faster you can develop next application, which means more money for you.
Usual way of using debugger is after encountering program malfunction to better analyze reasons that led to unexpected behavior and in the end to eliminate those reasons (i.e. bugs). On the other hand, code verification tools are used during program development to pinpoint possible problematic locations which could eventually lead to bugs in program – so debuggers are used to eliminate bugs once they are in program, code validation tools are used to prevent bugs from appearing in the program in the first place.
Simple example
Let’s consider this simple PHP script (schedule.php) to illustrate how those tools work:
[code language="php"] SID = $SID; } function set_SDate($SDate) { $this->SDate = $SDate; } function set_flights($flights) { $this->flights = $flights; } // Get methods function get_SID() { return $this->SID; } function get_SDate() { return $this->SDate; } function get_flights() { return $this->fligths; } function __construct($sid, $sdate, $flights) { $this->SID = $sid; $this->SDate = $sdate; $flights = split(';', $flights); $this->flights = array(); for ($i = 0; $i < count($flight); $i++) $this->flights[] = $i . '. ' . $flight[$i]; } } ?> [/code]
After invoking code validation tool (example how it looks within Eclipse), we are presented with tool’s report:
As we can see in the report are mentioned 3 potentially problematic spots which should be closer inspected by programmer – in two of those there is obviously typo in variable/property name, and in third case tool issued warning about possible performance penalty of using function call in condition part of loop. We can see that it only took less than a second to detect 2 bugs and 1 performance tip, all without leaving development environment or starting program. Compared to classical debugging this is real time saver, not to say how difficult could be to trace those errors with debugger especially if class Schedule was part of bigger project. This is however just small fraction of checks that code validation tools usually performs.
What you need for quick start with code validation for PHP?
First of all you need tool itself (like Codenizer), then some IDE that supports PHP development (Eclipse or NetBeans would be smart choice), and plugin for integrating tool with IDE which can be found in the same location as tool (link).
Conclusion
It would be wrong to think of code validation as of some magic that would forever relieve you of using debugger and make you make bug-free code. Code validation can’t do that for you, but what it can do is to reduce your time spent debugging program by almost 80% and to help you spot the problems that could otherwise go unseen for very long time.
Enjoy this post?
Your vote will help us to grow this website and write more entries like this one :)
We available for hire! — Need help with a web or mobile project?
From yensdesign we develop technology projects based on web apps, mobile apps, consulting and databases. We are young and hard workers, passionate about innovation and focused in new technologies. We try to help you, sharing our knowledge acquired on worked projects, while helping the community and showing our capabilities.If you want to ask for a budget, we hare available for hire! Don't doubt in get in touch with us!.
Thank you for this post. Can you plz make a tut for beginners, step-by-step.
looks useful, I’m gonna try out something new too, I like usually debugging tool as Firefox extension, but maybe there’s some other better way.
Thank you for this post. The tool looks very useful. I will try it out and then share my experience.
I truly loved reading your post. Thanks