php 语法检查器和服务器不一致。语法检查器是否正确?

发布于 2024-11-26 00:58:40 字数 1659 浏览 4 评论 0原文

我指的语法检查器是一个我曾经使用过的简洁的小工具在通过我们的 tortoiseSVN 提交代码之前帮助我检查代码。直到今天它才让我误入歧途。

我做了一个简单的函数来查找传入数字的数量级,不完整,但包含在下面:

function( $graphMax )
{
$a = (int)log10( $graphMax );
echo "<br><br>GRAPHMAX LOG-10: " . $a . "<br><br>";
$a = pow( 10 , $a );
return $a;
}

这将返回该数量级的最低值(对于 10,000-99,999 之间的数字为 10,000 )。

我遇到的问题是函数的这一部分:

$a = (int)log10( $graphMax );

语法检查器说,当我将整个文件复制/粘贴到其中时,语法中没有错误,但是当我提交并在我们的服务器上运行它时,我得到:

Parse error: syntax error, unexpected '(', expecting T_STRING in /*/global_functions.php on line 364

< em>根据要求,这是函数上方的代码:

function countSections( $testID )

{ 需要('config.php');

//Connect to database server
$dsl_sqlh = mysql_connect( $dsl_db_host, $dsl_db_user , $dsl_db_pass )
      or die ("Unable to connect");
mysql_select_db ( $dsl_db , $dsl_sqlh) or die ("Unable to select database");

//Get Section ID.
//With this we can query the correct section 
$secQuery = sprintf("SELECT test_section_name FROM v_ak47_test_section WHERE ak47_testhistory_id= $testID and obsolete = 0");
$secResults = mysql_query($secQuery , $dsl_sqlh);
$rows = mysql_num_rows( $secResults );  

if( $rows > 0 )
{   
    return $rows;
}
else
{
    echo "<br><br>Test has no sections! Check test ID provided.<br><br>";
    return null;
}

}

答案:我没有命名该函数。我不知道我是怎么错过的。还早...我需要更多咖啡:(谢谢大家的帮助!抱歉,太反气氛了。我最近的几篇文章都是这样的。

The syntax checker I am referring to is a neat little tool that I've used to help me check my code before committing it over our tortoiseSVN. It's never lead me astray until today.

I've made a simple function to find the order of magnitude of a number passed in, incomplete but included below:

function( $graphMax )
{
$a = (int)log10( $graphMax );
echo "<br><br>GRAPHMAX LOG-10: " . $a . "<br><br>";
$a = pow( 10 , $a );
return $a;
}

This will return the lowest value of that order of magnitude( 10,000 for numbers between 10,000-99,999 ).

The issue I am having is this part of the function:

$a = (int)log10( $graphMax );

The syntax checker says that there are no errors in the syntax when I copy/paste the entire file into it, but when I submit and run it on our server, I get:

Parse error: syntax error, unexpected '(', expecting T_STRING in /*/global_functions.php on line 364

as requested, this is the code above the function:

function countSections( $testID )

{
require( 'config.php');

//Connect to database server
$dsl_sqlh = mysql_connect( $dsl_db_host, $dsl_db_user , $dsl_db_pass )
      or die ("Unable to connect");
mysql_select_db ( $dsl_db , $dsl_sqlh) or die ("Unable to select database");

//Get Section ID.
//With this we can query the correct section 
$secQuery = sprintf("SELECT test_section_name FROM v_ak47_test_section WHERE ak47_testhistory_id= $testID and obsolete = 0");
$secResults = mysql_query($secQuery , $dsl_sqlh);
$rows = mysql_num_rows( $secResults );  

if( $rows > 0 )
{   
    return $rows;
}
else
{
    echo "<br><br>Test has no sections! Check test ID provided.<br><br>";
    return null;
}

}

Answer: I didn't name the function. I have no idea how I missed that. It's early... I need more coffee:( Thanks for the help everyone! Sorry it was so anti-climatic. My last few posts have been like this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

为你鎻心 2024-12-03 00:58:40

您需要给您的函数命名

function {ENTER NAME HERE}( $graphMax )
{
   $a = (int)log10( $graphMax );
   echo "<br><br>GRAPHMAX LOG-10: " . $a . "<br><br>";
   $a = pow( 10 , $a );
   return $a;
}

You need to give your function a name

function {ENTER NAME HERE}( $graphMax )
{
   $a = (int)log10( $graphMax );
   echo "<br><br>GRAPHMAX LOG-10: " . $a . "<br><br>";
   $a = pow( 10 , $a );
   return $a;
}
汹涌人海 2024-12-03 00:58:40

差异很可能是您在服务器上运行 PHP 5.2,但在运行语法检查器(默认)时检查了 5.3。 5.2 中不允许使用匿名函数,但 5.3 中允许。检查 5.2 选项并再次运行语法检查器,您将得到与报告的相同的错误。

http://php.net/manual/en/functions.anonymous.php

你的语法有效的5.3,它只是没有做任何事情。

如有疑问,请相信服务器所说的:)

The difference is most likely that you are running PHP 5.2 on the server, but have 5.3 checked off when you run the syntax checker (default). Anonymous functions are not allowed in 5.2, but are in 5.3. Check the 5.2 option and run the syntax checker again, you will get the same error you reported.

http://php.net/manual/en/functions.anonymous.php

Your syntax is valid 5.3, it's just not doing anything.

When in doubt, trust what the server says :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文