2014-02-27 62 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. 
解決這個問題