phplint未声明的功能

时间:2014-02-27 12:04:48

标签: php sublime-text-plugin phplint

我正在使用 phplint 来检查我的PHP代码。我是Windows 8.1,我的编辑器是Sublime Text 3。 这是我的一小段代码片段:

<?php
header("Content-type: image/png");

$singleHeight = 129;
$singleWidth = 97;
$bild = imagecreatetruecolor(1170, 520);
$orange = imagecolorallocate($bild, 248, 154, 38);
imagefill($bild, 0, 0, $orange);

....

?>

这是phplint报告:

1:函数'header()'(仍未)声明。根据其使用情况猜测签名。提示:最好在使用之前声明这些功能     1:未声明的函数'header()'只使用一次:拼写错误?
    3:变量'$ singleHeight'已分配但从未使用过     4:变量'$ singleWidth'已分配但从未使用过     5:函数'imagecreatetruecolor()'(仍未)声明。根据其使用情况猜测签名。提示:最好在使用之前声明这些功能     5:未声明的函数'imagecreatetruecolor()'仅使用一次:拼写错误?
    6:函数'imagecolorallocate()'(仍未)声明。根据其使用情况猜测签名。提示:最好在使用之前声明这些功能     6:未声明的函数'imagecolorallocate()'仅使用一次:拼写错误?     7:函数'imagefill()'(仍未)声明。根据其使用情况猜测签名。提示:最好在使用之前声明这些功能     7:未声明的函数'imagefill()'只使用一次:拼写错误?

未声明的功能是什么?代码本身工作正常。

1 个答案:

答案 0 :(得分:0)

我假设您正在使用此PHPLint http://www.icosaedro.it/phplint/phplint-on-line.html

默认情况下它似乎没有加载任何标准库,所以当你检查代码时,linter是从头开始的,没有声明任何内容。

当您在服务器上运行代码时,GD和标准PHP函数(如标题)之类的东西都会启用,因此它可以正常工作。

您可以通过将这些库添加到代码顶部来解决此问题,如此

<?php /*. require_module 'gd'; .*/ ?>
<?php /*. require_module 'standard'; .*/ ?>
<?php
header("Content-type: image/png");

$singleHeight = 129;
$singleWidth = 97;
$bild = imagecreatetruecolor(1170, 520);
$orange = imagecolorallocate($bild, 248, 154, 38);
imagefill($bild, 0, 0, $orange);

这将输出如此

BEGIN parsing of test-32AOqf
1:      <?php /*. require_module 'gd'; .*/ ?>
2:      <?php /*. require_module 'standard'; .*/ ?>
3:      <?php
4:      header("Content-type: image/png");
5:      
6:      $singleHeight = 129;
7:      $singleWidth = 97;
8:      $bild = imagecreatetruecolor(1170, 520);
9:      $orange = imagecolorallocate($bild, 248, 154, 38);
10:     imagefill($bild, 0, 0, $orange);
END parsing of test-32AOqf
==== test-32AOqf:7: notice: variable `$singleWidth' assigned but never used
==== test-32AOqf:6: notice: variable `$singleHeight' assigned but never used
==== ?: notice: unused package `stdlib/dummy.php'
==== ?: notice: unused module `mysql'
==== ?: notice: unused module `pcre'
==== ?: notice: required module `standard'
==== ?: notice: required module `gd'
Overall test results: 0 errors, 0 warnings.