FAQ
Edit report at http://pear.php.net/bugs/bug.php?id=17265&edit=1

ID: 17265
Updated by: gsherwood@squiz.net
Reported By: lars-codesniff at ukmix dot net
Summary: Require all variables to be declared before using
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: PHP_CodeSniffer
Package Version: 1.2.2
PHP Version: 5.2.12
-Assigned To:
+Assigned To: squiz
Roadmap Versions:
New Comment:

-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: squiz
I'm closing this report because I'm not adding any new sniffs to PHPCS
unless:
- One gets contributed by someone
- PEAR needs it because of a change to the standard
- I happen to need it for something

May as well not leave this request open when I'm not going to be able to
get around to it due to other commitments.

Thank you for your suggestion though. If anyone wants to contribute a
sniff for this, please re-open this report.


Previous Comments:
------------------------------------------------------------------------

[2010-11-16 13:34:20] black

https://github.com/AlanOne/PHP_Codesniffer-Plugins

Here you have a few sniffs. They are afaik not up to
PHP_CodeSniffer/PEAR coding standards, but if that bothers you, and you
want to see this added into CodeSniffer, you can submit patches on
github (or any other reason, contribute ;))

BR,
Tit

------------------------------------------------------------------------

[2010-07-20 07:41:20] black

P.s. I'm working on a sniff to check variable use, a standalone test is
already working. If you have additional comments or wishes for this
functionality, speak up now ;)

------------------------------------------------------------------------

[2010-07-20 07:11:40] black

Is this really necessary? The thing to realize is, that you usually have
5 variables in the function domain:

1. arguments
2. globals
3. autoglobals ($_SESSION, $_GET,...)
4. variables that you read from
5. variables that you write to ($thing in your case).

In the example you provided, we can see that $thing is being set, and
shouldn't be defined additionally. However, there are cases, where this
is not so simple, for example:

exec("cat /etc/hosts", $retval);

In this case, $retval is being modified. But, as we would parse the
code, we would think $retval is being used without being defined, and
would force the programmer to add $retval = array(); before calling
exec, to avoid the error.

What do you think?

------------------------------------------------------------------------

[2010-03-25 15:13:25] lars

Description:
------------
Our coding conventions require all variables are "declared" at the top
of a function, for example:

function printThings($things)
{
$thing = null;

foreach($things as $thing)
{
echo $thing;
}
}

A sniff to detect failure to "declare" $thing above would be very
useful.

------------------------------------------------------------------------

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedApr 20, '11 at 5:41a
activeApr 20, '11 at 5:41a
posts1
users1
websitepear.php.net

1 user in discussion

Gsherwood: 1 post

People

Translate

site design / logo © 2021 Grokbase