|
Posted by Umberto Salsi on 10/14/05 19:14
Colin McKinnon <colin.thisisnotmysurname@ntlworld.deletemeunlessURaBot.com> wrote:
> phplint is an interesting tool but it was originally designed for the
> express purpose of making PHP behave as if it were not dynamically typed -
> so you're likely to have problems seeing the wood for the trees unless you
> use PHP to run your Java/C++ programs ;) Although I'll concede that PHP
> might benefit from something like Perl's strict mode.
>
> IIRC the Zend IDE will do this and can also track code coverage - which is
> likely to be much more beneficial.
IMHO, Perl (with or without the "strict" option) is the stone age of the
safe programming, and I will not consider it here. I never used the Zend
IDE, but I intend to try it.
The aim of the PHPLint project is not to "turn PHP into Java", but
instead to provide a development and debugging tool without boring the
programmer with lots of useless code, so preserving the easiness of
the language with minimal impact on the habits of the PHP programmers.
Most of the existing code can be validated effectively with PHPLint,
possibly with only few changes. For example, converting the phpmailer
class (http://phpmailer.sourceforge.net/) from "plain PHP source" to
"PHPLint-compliant source" took me about one hour: most of the methods
were used before being declared (PHPLint is a single-pass parser) so I
needed to move them upward; for some of the methods PHPLint was unable to
detect the type of the returned value, and some formal arguments needed
to be formally declared, like in this example:
/**
* Adds a "Cc" address. Note: this function works
* with the SMTP mailer on win32, not with the "mail"
* mailer.
* @param string $address <-- REDUNDANT
* @param string $name <-- REDUNDANT
* @return void <-- REDUNDANT
*/
function AddCC(/*. string .*/ $address, $name = "") {
$cur = count($this->cc);
$this->cc[$cur][0] = trim($address);
$this->cc[$cur][1] = $name;
}
Note that only the type of the argument $address required to be
specified, since PHPLint was unable to guess it by itself: this is
the only change made. The types of $name (string) and of the local
variable $cur (int) are guessed successfully, so they do not require
to be declared formally. Also the type of the returned value (void) is
detected automatically by PHPLint. Note too that the declarations of the
PHPDocumentator (@param, @return) are now redundant (I hope to complete
the work either integrating PHPLint inside PHPDocumentator or vice-versa).
Doing that, I found a little bug: phpmailer::SMTPDebug is boolean,
where SMTP::do_debug is int, and the two values are mixed inside
phpmailer::SmtpConnect(). In this case, PHP convert the TRUE value into
int(1) so the program runs without errors, but probably this isn't what
the programmer intended to do.
All the work done on this class is not merely the validation of its source:
now I can to validate all the other programs that require it.
Regard,
___
/_|_\ Umberto Salsi
\/_\/ www.icosaedro.it
Navigation:
[Reply to this message]
|