php 编辑器/编译器/任何显示我的代码中的错误的内容

发布于 2024-09-19 03:27:20 字数 442 浏览 5 评论 0原文

假设我有一些代码:

  <?php
  echo "Hello Everybody!";
  echo "<br/>" ;
  $var1 = 23 ;  
  var_dump($var1)   ;

  $str = <<<HERE

  some random text
  more random strings

  HERE;

  echo $str ;
?>

现在在 localhost 上将其作为 index.php 运行,给出一个空白页面。那可能是因为代码中有一些错误。现在有什么东西(编辑器,编译器,等等)可以准确地告诉我错误在哪里以及是什么?

目前,我使用其中一个便携式服务器(XAMP、netserver、uniserver)来运行我的 php 页面,效果很好,但它没有告诉我代码中存在哪些错误。

谢谢

Lets say I have some code:

  <?php
  echo "Hello Everybody!";
  echo "<br/>" ;
  $var1 = 23 ;  
  var_dump($var1)   ;

  $str = <<<HERE

  some random text
  more random strings

  HERE;

  echo $str ;
?>

Now running this as index.php on localhost , gives a blank page. Thats probably because there is some error in the code. Now is there something(editor,compiler,whatever) that will tell me exactly where and what my error is ?

Currently I use one of those portable servers (XAMP , netserver,uniserver) to run my php pages, which works good , but it doesn't tell me what errors are there in my code.

Thanks

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

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

发布评论

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

评论(6

作业与我同在 2024-09-26 03:27:20

为此,您应该使用的工具是 PHP。

确保 error_reporting 设置为较高的值,例如 E_STRICT

在 PHP 5 中,提供了新的错误级别 E_STRICT。由于 E_STRICT 未包含在 E_ALL 中,因此您必须显式启用此类错误级别。在开发过程中启用 E_STRICT 有一些好处。 STRICT 消息将帮助您使用最新、最好的建议编码方法,例如警告您有关使用已弃用的函数。

The tool you should use for this is PHP.

Make sure error_reporting is set to something high, such as E_STRICT:

In PHP 5 a new error level E_STRICT is available. As E_STRICT is not included within E_ALL you have to explicitly enable this kind of error level. Enabling E_STRICT during development has some benefits. STRICT messages will help you to use the latest and greatest suggested method of coding, for example warn you about using deprecated functions.

家住魔仙堡 2024-09-26 03:27:20

我就让其他人来回答小编的问题吧。我将回答代码中的错误部分:

  HERE;

HERE;

有前导空格.string.syntax.heredoc" rel="nofollow noreferrer">heredoc 结束。从手册中:

结束标识符必须从该行的第一列开始。此外,标识符必须遵循与 PHP 中任何其他标签相同的命名规则:它必须仅包含字母数字字符和下划线,并且必须以非数字字符或下划线开头。

I'll let others to answer the question of the editor. I'll answer the error part in the code:

  HERE;

to

HERE;

There should be no leading space where the heredoc ends. From the manual:

The closing identifier must begin in the first column of the line. Also, the identifier must follow the same naming rules as any other label in PHP: it must contain only alphanumeric characters and underscores, and must start with a non-digit character or underscore.

遗心遗梦遗幸福 2024-09-26 03:27:20

检查您的 php.ini 以查看是否 error_reporting 已关闭。

Check your php.ini to see if error_reporting is turned off.

骑趴 2024-09-26 03:27:20

许多 IDE 都提供此功能 - 在某种程度上,我想到的是 NetBeans、Dreamweaver CS5。

他们会突出显示明显的语法错误,例如缺少分号/不平衡的括号。

但请记住,如果编译器可以识别每个错误,那么他们也可以修复它们。没有任何想法可以帮助修复不良的编程逻辑等。

同样作为下面突出显示的答案,可以关闭 error_reporting,因此应该打开以进行开发。

Many IDEs offer this functionality - NetBeans being one that comes to mind, Dreamweaver CS5 to a certain extent.

They will highlight blatant syntax errors like missing semicolons/unbalanced bracers.

But bear in mind if a compiler could identify every error then they could fix them too. no idea will help fix poor programming logic etc.

also as an answer below highlights, error_reporting can be turned off so should be turned on for development.

半衬遮猫 2024-09-26 03:27:20

创建新页面,将其命名为index.php

error_reporting(E_ALL);
ini_set("display_errors", 1);
include('content.php');

content.php 应该是您的代码所在的页面,

现在它将显示您的错误!
另外,我几天前在 tmp 服务器上工作时注意到了一个问题。

Make new page, call it index.php

error_reporting(E_ALL);
ini_set("display_errors", 1);
include('content.php');

content.php should be the page where your code is,

Now it will show your error!
Also i problem i noticed couple of days ago when you're working on a tmp-server.

岁月无声 2024-09-26 03:27:20

仅供参考,如果您只想进行快速语法检查,请对 php 二进制文件使用 -l 开关。

php -l myscript.php

FYI, if you just want to do a quick syntax check, use the -l switch with the php binary.

php -l myscript.php

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