2014-02-27 118 views
3

我使用phplint检查我的PHP代码。我嗡的Windows 8.1和我的编辑是崇高的文本3 这是我的一个小代码片段:phplint未申报功能

<?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:功能“头()”(仍然)没有宣布。从使用中猜测签名。提示:最好在使用前声明函数
1:未声明的函数'header()'只能使用一次:拼写错误?
3:变量 '$ singleHeight' 分配,但从未使用
4:变量 '$ singleWidth' 分配,但从未使用
5:函数 'imagecreatetruecolor()'(仍然)不声明。从使用中猜测签名。提示:最好在使用之前声明这些函数
5:未声明的函数'imagecreatetruecolor()'只能使用一次:拼写错误?
6:函数'imagecolorallocate()'(仍然)没有声明。从使用中猜测签名。提示:最好在使用之前声明函数
6:未声明的函数'imagecolorallocate()'只能使用一次:拼写错误? 7:函数'imagefill()'(仍然)没有声明。从使用中猜测签名。提示:最好在使用之前声明这些函数
7:未声明的函数'imagefill()'只能使用一次:拼写错误?

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

回答

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. 
解决这个问题