PHP解析/语法错误;以及如何解决它们

发布于 2025-01-26 07:37:39 字数 10568 浏览 6 评论 0 原文

每个人都遇到语法错误。即使是经验丰富的程序员也会错别字。对于新移民来说,这只是学习过程的一部分。但是,通常很容易解释错误消息,例如:

php解析错误:语法错误,在第20行上的index.php中出乎意料的'{'

意外符号并不总是真正的罪魁祸首。但是,线号对从哪里开始寻找大概的想法。

始终查看代码上下文。语法错误通常隐藏在以前的代码行中提到的。将您的代码与手册中的语法示例进行比较。

虽然并非每种情况都匹配对方。然而,有一些 解决语法错误的一般步骤 。 此引用总结了常见的陷阱:

紧密相关的引用:

和:

尽管Stack Overflow也欢迎新秀编码人员,但它主要针对专业编程问题。

  • 回答每个人的编码错误和狭窄的错别字。
  • 因此,请花一些时间按照基本步骤,在发布语法修复请求之前。
  • 如果您仍然需要,请展示您自己的解决计划,尝试修复程序以及有关外观或可能出错的思考过程。

如果您的浏览器显示错误消息,例如“ Syntaxerror:非法字符”,那么它实际上不是 php - 相关,但是a javascript - stytax错误


在供应商代码上提出的语法错误:最后,考虑一下,如果不是通过编辑您的代码库来提出语法错误,但是在安装或升级外部供应商软件包后,可能是由于PHP版本不兼容,所以根据您的平台设置检查供应商的要求。

Everyone runs into syntax errors. Even experienced programmers make typos. For newcomers, it's just part of the learning process. However, it's often easy to interpret error messages such as:

PHP Parse error: syntax error, unexpected '{' in index.php on line 20

The unexpected symbol isn't always the real culprit. But the line number gives a rough idea of where to start looking.

Always look at the code context. The syntax mistake often hides in the mentioned or in previous code lines. Compare your code against syntax examples from the manual.

While not every case matches the other. Yet there are some general steps to solve syntax mistakes.
This references summarized the common pitfalls:

Closely related references:

And:

While Stack Overflow is also welcoming rookie coders, it's mostly targetted at professional programming questions.

  • Answering everyone's coding mistakes and narrow typos is considered mostly off-topic.
  • So please take the time to follow the basic steps, before posting syntax fixing requests.
  • If you still have to, please show your own solving initiative, attempted fixes, and your thought process on what looks or might be wrong.

If your browser displays error messages such as "SyntaxError: illegal character", then it's not actually -related, but a -syntax error.


Syntax errors raised on vendor code: Finally, consider that if the syntax error was not raised by editing your codebase, but after an external vendor package install or upgrade, it could be due to PHP version incompatibility, so check the vendor's requirements against your platform setup.

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

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

发布评论

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

评论(21

黑白记忆 2025-02-02 07:37:39

语法错误是什么?

PHP属于 c-style 命令编程语言。它具有严格的语法规则,在遇到放错位置符号或标识符时无法从中恢复。它无法猜测您的编码意图。

“函数定义语法摘要”

最重要的提示,

您可以始终采取一些基本的预防措施:

如何解释解析器错误

典型的语法错误消息读取:

解析错误:语法错误,出乎意料的 t_string ,期望'; '' file.php on <强>线 217

列出了语法错误的可能的位置。请参阅提到的文件名线号

a noriker 例如 t_string 解释了哪个符号的解析器/tokenizer无法最终处理。但是,这不一定是语法错误的原因。

还必须研究以前的代码行。通常,语法错误只是较早发生的不幸。错误行号只是解析器最终放弃处理所有问题的地方。

解决语法错误

有许多方法可以缩小和修复语法打ic。

  • 打开提到的源文件。查看上述代码线

    • 对于失控的字符串和放错的操作员,通常是您找到罪魁祸首的地方。

    • 读取从左到右的线,想象每个符号的作用。

  • 更常规的是,您还需要查看上线

    • 特别是,缺少; 在上一行的末端/语句中缺少半隆。 (至少从风格的角度来看。)

    • 如果 {代码块} 是错误的关闭或嵌套,则可能需要进一步调查源代码。使用适当的代码凹痕来简化。

  • 查看语法着色

    • 字符串,变量和常数都应具有不同的颜色。

    • 运算符+ - */。也应被不同。否则它们可能处于错误的上下文。

    • 如果您看到字符串着色延伸太远或太短,则您发现了一个毫无疑问的或缺少关闭”或''字符串标记。

    • 彼此之间有两个相同的标点符号也可能意味着麻烦。通常,如果不是 ++ , - 或操作员之后的括号,则操作员是唯一的。在大多数情况下,两个字符串/标识符彼此互相关注。

  • Whitespace是您的朋友
    遵循任何编码样式。

  • 暂时分解长线。

    • 您可以在操作员或常数和字符串之间自由 。然后,解析器将对解析错误的行号进行凝结。您可以隔离缺失或放错的语法符号,而不是查看非常冗长的代码。

    • 如果语句分为 条件。

    • 而不是冗长的数学公式或逻辑链,而是使用临时变量来简化代码。 (更可读=更少的错误。)

    • 在:

      之间添加新线

      1. 您可以轻松识别正确的代码,
      2. 您不确定的部分
      3. 以及解析器抱怨的线条。

      划分长代码块真的有助于找到语法错​​误的起源。

  • 评论有问题的代码。

    • 如果您无法隔离问题源,请开始评论(并因此暂时删除)代码块。

    • 一旦摆脱解析错误,就找到了问题来源。在那里更近距离看。

    • 有时您想暂时删除完整的功能/方法块。 (如果有无与伦比的卷发括号和错误的缩进代码。)

    • 当您无法解决语法问题时,尝试重写从头开始注释的部分

  • 作为新来者,避免一些令人困惑的语法构造。

    • 三元代码>? :条件操作员可以紧凑代码,并且确实很有用。但是在所有情况下,它都不有助于可读性。如果语句未经证实。

    • ,请使用普通

    • php的替代语法( if:/ elseif:/ endif; )对于模板而言是常见的,但可以说较容易容易遵循比正常 {代码<代码>} blocks。

  • 最普遍的新人错误是:

    • 缺少半洛龙; 用于终止语句/行。

    • 的不匹配的字符串引号“ '和unscaped引号。

    • 忘记的操作员,特别是字符串 convenation。

    • 不平衡括号。在报告的行中计算它们。有相等数量吗?

  • 不要忘记解决一个语法问题可能会发现下一个问题。

    • 如果您使一个问题消失了,但是在下面的某些代码中进行其他农作物,则您主要是正确的路径。

    • 如果编辑新的语法错误在同一行中播种后,则您的尝试更改可能是故障。 (并非总是如此。)

  • 如果无法修复,请还原以前工作代码的备份。

    • 采用源代码版本控制系统。您始终可以查看损坏和最后一个工作版本的 diff 。关于语法问题是什么,这可能是启发性的。
  • 看不见的杂散unicode字符:在某些情况下,您需要在您的来源上使用六边形或其他编辑器/查看器。仅通过查看您的代码就找不到一些问题。

  • 注意哪种类型的线折扣保存在文件中。

    • php Just honors \ n newlines,而不是 \ r 马车返回。

    • 这有时是MacOS用户的问题(即使在OS&nbsp; x上也适用于错误配置的编辑器)。

    • 单行 // 注释时,它通常仅作为问题浮出水面。 Multiline //......./ 评论很少在忽略线路破裂时打扰解析器。

  • 如果您的语法错误不会通过网络传输
    碰巧的是,您的计算机上有语法错误。但是在线发布同一文件不再显示出来。这只能意味着两件事之一:

    • 您正在查看错误的文件!

    • 或您的代码包含不可见的杂物Unicode(请参见上文)。
      您可以轻松发现:只需将代码从Web表单复制回文本编辑器。

  • 检查您的 PHP版本。并非所有语法构造都可以在每个服务器上提供。

    • php -v 用于命令行解释器

    • &lt;?php phpinfo(); 是通过Web服务器调用的。

    这些不一定是相同的。特别是在使用框架时,您将它们匹配。

  • 不要使用 php的保留关键字作为函数/方法,类或常数的标识符。

  • 反复试验是您的最后一个度假胜地。

如果所有其他方法都失败了,则可以始终 Google 您的错误消息。语法符号并不那么容易搜索(堆栈溢出本身由 symborhound )。因此,在找到相关的内容之前,可能需要浏览几页。

进一步指南:

白屏幕死亡屏幕

,如果您的网站只是空白,则通常是原因。
使用以下方式启用其显示:

  • error_reporting = e_all
  • display_errors = 1

在您的 php.ini 通常,或通过 .htaccess 对于mod_php,
甚至 .user.ini 使用FastCGI设置。

在损坏脚本中启用它为时已晚,因为PHP甚至无法解释/运行第一行。快速的解决方法正在制作包装脚本,例如 test.php

<?php
   error_reporting(E_ALL);
   ini_set("display_errors", 1);
   include("./broken-script.php");

然后通过访问此包装脚本来调用失败代码。

它还有助于启用PHP的 error_log ,并查看您的 webserver的 error.log 当脚本用HTTP 500响应崩溃时。

What are the syntax errors?

PHP belongs to the C-style and imperative programming languages. It has rigid grammar rules, which it cannot recover from when encountering misplaced symbols or identifiers. It can't guess your coding intentions.

Function definition syntax abstract

Most important tips

There are a few basic precautions you can always take:

  • Use proper code indentation, or adopt any lofty coding style.
    Readability prevents irregularities.

  • Use an IDE or editor for PHP with syntax highlighting.
    Which also help with parentheses/bracket balancing.

    Expected: semicolon

  • Read the language reference and examples in the manual.
    Twice, to become somewhat proficient.

How to interpret parser errors

A typical syntax error message reads:

Parse error: syntax error, unexpected T_STRING, expecting ';' in file.php on line 217

Which lists the possible location of a syntax mistake. See the mentioned file name and line number.

A moniker such as T_STRING explains which symbol the parser/tokenizer couldn't process finally. This isn't necessarily the cause of the syntax mistake, however.

It's important to look into previous code lines as well. Often syntax errors are just mishaps that happened earlier. The error line number is just where the parser conclusively gave up to process it all.

Solving syntax errors

There are many approaches to narrow down and fix syntax hiccups.

  • Open the mentioned source file. Look at the mentioned code line.

    • For runaway strings and misplaced operators, this is usually where you find the culprit.

    • Read the line left to right and imagine what each symbol does.

  • More regularly you need to look at preceding lines as well.

    • In particular, missing ; semicolons are missing at the previous line ends/statement. (At least from the stylistic viewpoint. )

    • If { code blocks } are incorrectly closed or nested, you may need to investigate even further up the source code. Use proper code indentation to simplify that.

  • Look at the syntax colorization!

    • Strings and variables and constants should all have different colors.

    • Operators +-*/. should be tinted distinct as well. Else they might be in the wrong context.

    • If you see string colorization extend too far or too short, then you have found an unescaped or missing closing " or ' string marker.

    • Having two same-colored punctuation characters next to each other can also mean trouble. Usually, operators are lone if it's not ++, --, or parentheses following an operator. Two strings/identifiers directly following each other are incorrect in most contexts.

  • Whitespace is your friend.
    Follow any coding style.

  • Break up long lines temporarily.

    • You can freely add newlines between operators or constants and strings. The parser will then concretize the line number for parsing errors. Instead of looking at the very lengthy code, you can isolate the missing or misplaced syntax symbol.

    • Split up complex if statements into distinct or nested if conditions.

    • Instead of lengthy math formulas or logic chains, use temporary variables to simplify the code. (More readable = fewer errors.)

    • Add newlines between:

      1. The code you can easily identify as correct,
      2. The parts you're unsure about,
      3. And the lines which the parser complains about.

      Partitioning up long code blocks really helps to locate the origin of syntax errors.

  • Comment out offending code.

    • If you can't isolate the problem source, start to comment out (and thus temporarily remove) blocks of code.

    • As soon as you got rid of the parsing error, you have found the problem source. Look more closely there.

    • Sometimes you want to temporarily remove complete function/method blocks. (In case of unmatched curly braces and wrongly indented code.)

    • When you can't resolve the syntax issue, try to rewrite the commented out sections from scratch.

  • As a newcomer, avoid some of the confusing syntax constructs.

    • The ternary ? : condition operator can compact code and is useful indeed. But it doesn't aid readability in all cases. Prefer plain if statements while unversed.

    • PHP's alternative syntax (if:/elseif:/endif;) is common for templates, but arguably less easy to follow than normal { code } blocks.

  • The most prevalent newcomer mistakes are:

    • Missing semicolons ; for terminating statements/lines.

    • Mismatched string quotes for " or ' and unescaped quotes within.

    • Forgotten operators, in particular for the string . concatenation.

    • Unbalanced ( parentheses ). Count them in the reported line. Are there an equal number of them?

  • Don't forget that solving one syntax problem can uncover the next.

    • If you make one issue go away, but other crops up in some code below, you're mostly on the right path.

    • If after editing a new syntax error crops up in the same line, then your attempted change was possibly a failure. (Not always though.)

  • Restore a backup of previously working code, if you can't fix it.

    • Adopt a source code versioning system. You can always view a diff of the broken and last working version. Which might be enlightening as to what the syntax problem is.
  • Invisible stray Unicode characters: In some cases, you need to use a hexeditor or different editor/viewer on your source. Some problems cannot be found just from looking at your code.

    • Try grep --color -P -n "\[\x80-\xFF\]" file.php as the first measure to find non-ASCII symbols.

    • In particular BOMs, zero-width spaces, or non-breaking spaces, and smart quotes regularly can find their way into the source code.

  • Take care of which type of linebreaks are saved in files.

    • PHP just honors \n newlines, not \r carriage returns.

    • Which is occasionally an issue for MacOS users (even on OS  X for misconfigured editors).

    • It often only surfaces as an issue when single-line // or # comments are used. Multiline /*...*/ comments do seldom disturb the parser when linebreaks get ignored.

  • If your syntax error does not transmit over the web:
    It happens that you have a syntax error on your machine. But posting the very same file online does not exhibit it anymore. Which can only mean one of two things:

    • You are looking at the wrong file!

    • Or your code contained invisible stray Unicode (see above).
      You can easily find out: Just copy your code back from the web form into your text editor.

  • Check your PHP version. Not all syntax constructs are available on every server.

    • php -v for the command line interpreter

    • <?php phpinfo(); for the one invoked through the webserver.

    Those aren't necessarily the same. In particular when working with frameworks, you will them to match up.

  • Don't use PHP's reserved keywords as identifiers for functions/methods, classes or constants.

  • Trial-and-error is your last resort.

If all else fails, you can always google your error message. Syntax symbols aren't as easy to search for (Stack Overflow itself is indexed by SymbolHound though). Therefore it may take looking through a few more pages before you find something relevant.

Further guides:

White screen of death

If your website is just blank, then typically a syntax error is the cause.
Enable their display with:

  • error_reporting = E_ALL
  • display_errors = 1

In your php.ini generally, or via .htaccess for mod_php,
or even .user.ini with FastCGI setups.

Enabling it within the broken script is too late because PHP can't even interpret/run the first line. A quick workaround is crafting a wrapper script, say test.php:

<?php
   error_reporting(E_ALL);
   ini_set("display_errors", 1);
   include("./broken-script.php");

Then invoke the failing code by accessing this wrapper script.

It also helps to enable PHP's error_log and look into your webserver's error.log when a script crashes with HTTP 500 responses.

我不是你的备胎 2025-02-02 07:37:39

我认为这个话题完全被过度讨论/过度复杂化。使用IDE是完全避免任何语法错误的方法。我什至会说,没有IDE的工作是不专业的。为什么?因为现代IDE在您输入的每个字符后检查您的语法。当您编码和整个行变红色时,一个很大的警告通知显示了语法错误的确切类型和确切位置,则绝对无需搜索其他解决方案。

使用语法检查IDE的意思是:

您(有效)您再也不会陷入语法错误,仅仅是因为您在键入时会看到它们正确。 。

  1. 认真 “> netbeans [free]
  2. phpstorm [$ 199 usd]
  3. eclipse with php插件 [免费]
  4. sublime [$ 80 USD](主要是文本编辑器,但可以使用插件扩展,例如 php语法parser

I think this topic is totally overdiscussed/overcomplicated. Using an IDE is THE way to go to completely avoid any syntax errors. I would even say that working without an IDE is kind of unprofessional. Why? Because modern IDEs check your syntax after every character you type. When you code and your entire line turns red, and a big warning notice shows you the exact type and the exact position of the syntax error, then there's absolutely no need to search for another solution.

Using a syntax-checking IDE means:

You'll (effectively) never run into syntax errors again, simply because you see them right as you type. Seriously.

Excellent IDEs with syntax check (all of them are available for Linux, Windows and Mac):

  1. NetBeans [free]
  2. PHPStorm [$199 USD]
  3. Eclipse with PHP Plugin [free]
  4. Sublime [$80 USD] (mainly a text editor, but expandable with plugins, like PHP Syntax Parser)
短叹 2025-02-02 07:37:39

出乎意料的 [

这些天,意外的 [数组括号通常在过时的PHP版本上看到。 短阵列语法是因为PHP = 5.4 = 5.4 。较旧的安装仅支持 array()

$php53 = array(1, 2, 3);
$php54 = [1, 2, 3];
         ⇑

阵列功能结果同样不适合较旧的PHP版本:

$result = get_whatever()["key"];
                      ⇑

参考 - 此错误在PHP中意味着什么? - “语法错误,出乎意料的 \ ['显示了最常见和最实用的解决方法。

不过,只需升级PHP安装即可,您总是最好。对于共享的Web托管计划,首先研究如果EG Sethandler PHP56-FCGI 可以用于启用更新的运行时。

另请参阅:

btw,也有预处理程序, php 5.4语法下传感器如果您真的很贴上较旧 +较慢的php版本。

意外的其他原因 [ 语法错误

如果不是PHP版本不匹配,则通常是一个普通的错别字或新的语法错误:

  • 您不能使用,甚至在PHP&nbsp; 7。

    中也没有

     保护$ var [“ x”] =“ nope”;
                  ⇑
     

  • 混淆 [与打开卷曲括号 {或括号是一个常见的疏忽。

      foreach [$ a as $ b)
            ⇑
     

    甚至:

     函数foobar [$ a,$ b,$ c] {
                   ⇑
     
  • 。或试图以数组的形式放置常数(php 5.6之前):

      $ var = const [123];
           ⇑
     

    至少php将 const 解释为常数名称。

    如果您打算访问数组变量(这是此处的典型原因),则添加领先的 $ sigil-因此,它将变成 $ varname 。 p>

  • 您正在尝试在关联数组成员上使用全局关键字。这不是有效的语法:

     全局$ var ['key'];
     

意外] 关闭 square bracket

这有些稀有,但是终端数组 支架。

  • 再次与括号或} 卷曲支架很常见:

     函数foobar($ a,$ b,$ c] {
                              ⇑
     
  • 或试图结束一个没有一个的数组:

      $ var = 2];
     

    通常发生在多线 nested 数组声明中。

      $ array = [1,[2,3],4,[5,6 [7,[8],[9,10]],11],12],15];
                                                 ⇑
     

    如果是这样,请使用您的IDE进行括号匹配以找到任何过早的] 数组闭合。至少使用更多的间距和新线来缩小范围。

Unexpected [

These days, the unexpected [ array bracket is commonly seen on outdated PHP versions. The short array syntax is available since PHP >= 5.4. Older installations only support array().

$php53 = array(1, 2, 3);
$php54 = [1, 2, 3];
         ⇑

Array function result dereferencing is likewise not available for older PHP versions:

$result = get_whatever()["key"];
                      ⇑

Reference - What does this error mean in PHP? - "Syntax error, unexpected \[" shows the most common and practical workarounds.

Though, you're always better off just upgrading your PHP installation. For shared webhosting plans, first research if e.g. SetHandler php56-fcgi can be used to enable a newer runtime.

See also:

BTW, there are also preprocessors and PHP 5.4 syntax down-converters if you're really clingy with older + slower PHP versions.

Other causes for Unexpected [ syntax errors

If it's not the PHP version mismatch, then it's oftentimes a plain typo or newcomer syntax mistake:

  • You can't use array property declarations/expressions in classes, not even in PHP 7.

    protected $var["x"] = "Nope";
                  ⇑
    
  • Confusing [ with opening curly braces { or parentheses ( is a common oversight.

    foreach [$a as $b)
            ⇑
    

    Or even:

    function foobar[$a, $b, $c] {
                   ⇑
    
  • Or trying to dereference constants (before PHP 5.6) as arrays:

    $var = const[123];
           ⇑
    

    At least PHP interprets that const as a constant name.

    If you meant to access an array variable (which is the typical cause here), then add the leading $ sigil - so it becomes a $varname.

  • You are trying to use the global keyword on a member of an associative array. This is not valid syntax:

    global $var['key'];
    

Unexpected ] closing square bracket

This is somewhat rarer, but there are also syntax accidents with the terminating array ] bracket.

  • Again mismatches with ) parentheses or } curly braces are common:

    function foobar($a, $b, $c] {
                              ⇑
    
  • Or trying to end an array where there isn't one:

    $var = 2];
    

    Which often occurs in multi-line and nested array declarations.

    $array = [1,[2,3],4,[5,6[7,[8],[9,10]],11],12]],15];
                                                 ⇑
    

    If so, use your IDE for bracket matching to find any premature ] array closure. At the very least use more spacing and newlines to narrow it down.

沧桑㈠ 2025-02-02 07:37:39

意外的t_variable

“意外 t_variable ”表示有一个文字 $ variable 名称,该名称不适合当前表达式/语句结构。

“有目的摘要/iNEXACT操作员+$

  1. 缺少semicolon

    最常见的是缺少的半olon 在上一行中。语句之后的可变分配是一个很好的指示:

     ×
     func1()
     $ var = 1 + 2; #在行中的解析错误+2
     
  2. 字符串串联

    频繁的不良事件是忘记操作员:

     ×
     打印“这是值得的:” $ value;
     

    顺便说一句,您应该喜欢 string interpolation (基本变量引用)每当有助于可读性时。避免了这些语法问题。

    字符串插值是脚本语言核心功能。利用它没有羞耻。忽略有关变量的任何微观优化建议。 不是。



  3. 缺少表达式操作员

    当然,其他表达式可能会出现同样的问题,例如算术操作:

     ×
     打印4 + 7 $ var;
     

    php不能猜测如果应该添加,减法或比较该变量等。

  4. lists < /H3>

    对于语法列表而言,例如在数组群体中,解析器还指示了预期的逗号例如:

     ×
     $ var = array(“ 1” =&gt; $ val,$ val2,$ val3 $ val4);
     

    或功能参数列表:

     ×
     函数myFunc($ param1,$ param2 $ param3,$ param4)
     

    等效地,您是否在 list global 语句中看到了这一点? >循环。

  5. 类声明

    此解析器错误也发生在类声明中。您只能分配静态常数,而不是表达式。因此,解析器抱怨变量作为分配的数据:

     类XYZ {
         var $ value = $ _get [“ input”];
     

    无与伦比的} 尤其可以在这里引导卷曲括号。如果方法终止得太早(使用适当的凹痕!),则通常将一个杂散变量放在类声明主体中。

  6. 标识符后变量

    您也永远无法拥有一个可变的drialible of clocter vishible 直接直接: /p>

     ×
     $ this-&gt; myfunc $ var();
     

    btw,这是一个常见的示例,其中意图是使用变量变量也许。在这种情况下

    请记住,使用变量应该是例外。新来者通常会试图过于随意地使用它们,即使阵列更简单,更合适。

  7. 语言构造后缺少括号

    急速打字可能会导致遗忘的开放或关闭括号
    对于 和 for foreach 语句:

     ×
     foreach $ array as $ key){
     

    解决方案:在语句和变量之间添加丢失的打开(。

     ×
     if($ var = pdo_query($ sql){
          $结果=…
     

    curly { brace不会打开代码块,而不会关闭使用使用>)首先关闭括号。

  8. 其他不期望条件

     ×
    else($ var&gt; = 0)
     

    解决方案:从 else 中删除条件或使用 elseif

  9. 需要封闭括号

     ×
    function()使用$ var {}
     

    解决方案:添加括号 $ var

  10. 无形的whitespace

    参考答案在“ Invisible Stray Unicode”上//en.wikipedia.org/wiki/non-breaking_space“ rel =“ noreferrer”>非破坏空间),您可能还会看到此错误的毫无戒心的代码,例如:

     &lt;?php
                              ⇐
    $ var = new PDO(...);
     

    在文件的开始和复制和贴上代码中相当普遍。请访问六角形,如果您的代码在视觉上似乎包含语法问题。

另请参见

Unexpected T_VARIABLE

An "unexpected T_VARIABLE" means that there's a literal $variable name, which doesn't fit into the current expression/statement structure.

purposefully abstract/inexact operator+$variable diagram

  1. Missing semicolon

    It most commonly indicates a missing semicolon in the previous line. Variable assignments following a statement are a good indicator where to look:

            ⇓
     func1()
     $var = 1 + 2;     # parse error in line +2
    
  2. String concatenation

    A frequent mishap are string concatenations with forgotten . operator:

                                    ⇓
     print "Here comes the value: "  $value;
    

    Btw, you should prefer string interpolation (basic variables in double quotes) whenever that helps readability. Which avoids these syntax issues.

    String interpolation is a scripting language core feature. No shame in utilizing it. Ignore any micro-optimization advise about variable . concatenation being faster. It's not.

  3. Missing expression operators

    Of course the same issue can arise in other expressions, for instance arithmetic operations:

                ⇓
     print 4 + 7 $var;
    

    PHP can't guess here if the variable should have been added, subtracted or compared etc.

  4. Lists

    Same for syntax lists, like in array populations, where the parser also indicates an expected comma , for example:

                                           ⇓
     $var = array("1" => $val, $val2, $val3 $val4);
    

    Or functions parameter lists:

                                     ⇓
     function myfunc($param1, $param2 $param3, $param4)
    

    Equivalently do you see this with list or global statements, or when lacking a ; semicolon in a for loop.

  5. Class declarations

    This parser error also occurs in class declarations. You can only assign static constants, not expressions. Thus the parser complains about variables as assigned data:

     class xyz {      ⇓
         var $value = $_GET["input"];
    

    Unmatched } closing curly braces can in particular lead here. If a method is terminated too early (use proper indentation!), then a stray variable is commonly misplaced into the class declaration body.

  6. Variables after identifiers

    You can also never have a variable follow an identifier directly:

                  ⇓
     $this->myFunc$VAR();
    

    Btw, this is a common example where the intention was to use variable variables perhaps. In this case a variable property lookup with $this->{"myFunc$VAR"}(); for example.

    Take in mind that using variable variables should be the exception. Newcomers often try to use them too casually, even when arrays would be simpler and more appropriate.

  7. Missing parentheses after language constructs

    Hasty typing may lead to forgotten opening or closing parenthesis
    for if and for and foreach statements:

            ⇓
     foreach $array as $key) {
    

    Solution: add the missing opening ( between statement and variable.

                           ⇓
     if ($var = pdo_query($sql) {
          $result = …
    

    The curly { brace does not open the code block, without closing the if expression with the ) closing parenthesis first.

  8. Else does not expect conditions

         ⇓
    else ($var >= 0)
    

    Solution: Remove the conditions from else or use elseif.

  9. Need brackets for closure

         ⇓
    function() use $var {}
    

    Solution: Add brackets around $var.

  10. Invisible whitespace

    As mentioned in the reference answer on "Invisible stray Unicode" (such as a non-breaking space), you might also see this error for unsuspecting code like:

    <?php
                              ⇐
    $var = new PDO(...);
    

    It's rather prevalent in the start of files and for copy-and-pasted code. Check with a hexeditor, if your code does not visually appear to contain a syntax issue.

See also

是伱的 2025-02-02 07:37:39

意外的t_constant_encapsed_string
意外的t_encapsed_and_whitespace

undieldy名称 t_constant_encapsed_string_string t_encapsed_and_whitespace 请参阅引号文字。

它们在不同的上下文中使用,但是语法问题非常相似。 t_encapsed…警告出现在双引号的字符串上下文中,而 t_constant…字符串通常误入歧途PHP表达式或语句。

  1. 不正确的变量插值

    ,对于不正确的PHP变量插值,它最常出现:

      s
    回声“这里是$错误[array']访问”;
     

    引用数组键是PHP上下文中必须的。但是在双引号(或Heredocs)中,这是一个错误。解析器抱怨包含的单个引号'string',因为它通常期望在那里有字面的标识符/键。

    更确切地说,使用php2-style 数组参考:

      echo“这只是$有效[此处] ...”;
     

    嵌套阵列或更深的对象引用,但是需要复杂的卷曲字符串表达式语法:

      echo“使用curly语法使用{$ array ['as_usual']}。
     

    如果不确定,通常使用更安全。它通常被认为更可读。更好的IDE实际上使用了不同的语法着色。

  2. 缺少串联

    如果字符串遵循表达式,但缺乏串联或其他操作员,那么您会看到PHP抱怨字符串字面:

     ×
    打印“你好”。世界 ” !”;
     

    虽然对您和我很明显,但PHP不能猜测 string string是在那里附加的。

  3. 混淆字符串报价外壳

    混淆字符串定界器时,发生了相同的语法错误。 。一个字符串由单个'或double 开始,引用也以相同的结尾。

     ×
    打印“&lt; a href =”'。 $链接。 '“”&gt;单击此处&lt;/a&gt;“;
          ⌞⎽⎽⎽⎽⎽⎽⎽⎽⌟⌞⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⌟⌞⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⌟
     

    该示例以双引号开头。但是双引号也注定是针对HTML属性的。然而,内部的预期串联操作员被解释为单引号中的第二个字符串的一部分。

    提示:将您的编辑器/IDE设置为单个和双引号的字符串使用略有不同的着色。 (这也有助于应用程序逻辑,更喜欢EG引用的文本输出的双引号字符串,而单一引用的字符串仅适用于恒定值。)

    这是一个很好的例子,您首先不应该突破双引号。相反,只需使用逃脱 html属性的报价:

      print“&lt; a href = \” {$ link} \“&gt;”&gt;单击此处&lt;/a&gt;“;
     

    虽然这也会导致语法混乱,但所有更好的IDE/编辑者都会以不同的方式着色。

  4. 丢失了 。

    等效地为忘记的打开 /code>/'引用解析器错误的食谱:

     ×
     make_url(登录','open');
     

    在这里,','将在裸词之后成为字符串字面,而显然登录是字符串参数。

  5. 如果您错过了逗号在数组创建块中,解析器将看到两个连续的字符串:

     数组(表)
         “键” =&gt; “价值”
         “ next” =&gt; “ ....”,
    );
     

    请注意,最后一行可能始终包含一个额外的逗号,但是在介于两者之间的一行是不可原谅的。如果没有语法突出显示,这很难发现。

  6. 功能参数列表

    同一件事用于函数调用

     ×
    myfunc(123,“文本”,和“更多”)
     
  7. 字符串

    一个常见的变化是简单地忘记的字符串终结者:

     ×
    mysql_evil(“从东西中选择 *);
    打印“'好'”;
          ⇑
     

    这里的PHP抱怨两个字符串文字直接彼此关注。但是真正的原因当然是未锁定的先前字符串。

  8. Heredoc凹痕

    先验 php 7.3

     打印&lt;&lt;&lt; html
        &lt; link ..&gt;
        html;
       ⇑
     

    解决方案:升级PHP或找到更好的寄养者。

另请参见

Unexpected T_CONSTANT_ENCAPSED_STRING
Unexpected T_ENCAPSED_AND_WHITESPACE

The unwieldy names T_CONSTANT_ENCAPSED_STRING and T_ENCAPSED_AND_WHITESPACE refer to quoted "string" literals.

They're used in different contexts, but the syntax issue are quite similar. T_ENCAPSED… warnings occur in double quoted string context, while T_CONSTANT… strings are often astray in plain PHP expressions or statements.

  1. Incorrect variable interpolation

    And it comes up most frequently for incorrect PHP variable interpolation:

                              ⇓     ⇓
    echo "Here comes a $wrong['array'] access";
    

    Quoting arrays keys is a must in PHP context. But in double quoted strings (or HEREDOCs) this is a mistake. The parser complains about the contained single quoted 'string', because it usually expects a literal identifier / key there.

    More precisely it's valid to use PHP2-style simple syntax within double quotes for array references:

    echo "This is only $valid[here] ...";
    

    Nested arrays or deeper object references however require the complex curly string expression syntax:

    echo "Use {$array['as_usual']} with curly syntax.";
    

    If unsure, this is commonly safer to use. It's often even considered more readable. And better IDEs actually use distinct syntax colorization for that.

  2. Missing concatenation

    If a string follows an expression, but lacks a concatenation or other operator, then you'll see PHP complain about the string literal:

                           ⇓
    print "Hello " . WORLD  " !";
    

    While it's obvious to you and me, PHP just can't guess that the string was meant to be appended there.

  3. Confusing string quote enclosures

    The same syntax error occurs when confounding string delimiters. A string started by a single ' or double " quote also ends with the same.

                    ⇓
    print "<a href="' . $link . '">click here</a>";
          ⌞⎽⎽⎽⎽⎽⎽⎽⎽⌟⌞⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⌟⌞⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⌟
    

    That example started with double quotes. But double quotes were also destined for the HTML attributes. The intended concatenation operator within however became interpreted as part of a second string in single quotes.

    Tip: Set your editor/IDE to use slightly distinct colorization for single and double quoted strings. (It also helps with application logic to prefer e.g. double quoted strings for textual output, and single quoted strings only for constant-like values.)

    This is a good example where you shouldn't break out of double quotes in the first place. Instead just use proper \" escapes for the HTML attributes´ quotes:

    print "<a href=\"{$link}\">click here</a>";
    

    While this can also lead to syntax confusion, all better IDEs/editors again help by colorizing the escaped quotes differently.

  4. Missing opening quote

    Equivalently are forgotten opening "/' quotes a recipe for parser errors:

                   ⇓
     make_url(login', 'open');
    

    Here the ', ' would become a string literal after a bareword, when obviously login was meant to be a string parameter.

  5. Array lists

    If you miss a , comma in an array creation block, the parser will see two consecutive strings:

    array(               ⇓
         "key" => "value"
         "next" => "....",
    );
    

    Note that the last line may always contain an extra comma, but overlooking one in between is unforgivable. Which is hard to discover without syntax highlighting.

  6. Function parameter lists

    The same thing for function calls:

                             ⇓
    myfunc(123, "text", "and"  "more")
    
  7. Runaway strings

    A common variation are quite simply forgotten string terminators:

                                    ⇓
    mysql_evil("SELECT * FROM stuffs);
    print "'ok'";
          ⇑
    

    Here PHP complains about two string literals directly following each other. But the real cause is the unclosed previous string of course.

  8. HEREDOC indentation

    Prior PHP 7.3, the heredoc string end delimiter can't be prefixed with spaces:

    print <<< HTML
        <link..>
        HTML;
       ⇑
    

    Solution: upgrade PHP or find a better hoster.

See also

梦亿 2025-02-02 07:37:39

意外的T_STRING

T_STRING 有点不正确。它没有引用“字符串” 。这意味着遇到了原始标识符。从裸露的单词到剩余的常数或功能名称,被遗忘的单字符串或任何纯文本。

  1. 错误引用的字符串

    此语法错误对于错误引用的字符串值最常见。任何UneScaped and Stray '报价都将形成无效的表达式:

      s
     echo“&lt; a href =“ http://example.com”&gt;单击此处&lt;/a&gt;“;
     

    语法突出显示将使这样的错误变得非常明显。重要的是要记住使用backSlashes逃脱 \“ double Qualtes或 \'单QUALES-取决于用作

  2. 为方便起见,在输出平原HTML时,您应该更喜欢外部引号。
  3. 如果要插值变量,请使用双引号字符串,但请注意逃脱字面的 double quotes。
  4. 对于更长的输出,更喜欢多个 echo /打印行,而不是逃脱进出。最好考虑A heredoc pection
  5. 另一个示例是使用PHP生成的HTML代码内的PHP条目:

      $ text ='&lt; div&gt; div&gt&gt;?
     

    如果 $ text 有很多线路,并且开发人员没有看到整个PHP变量值,并且专注于忘记其源的代码片段,则会发生这种情况。示例为在这里

    另请参见 PHP中的单引号和双引号的字符串有什么区别?

  6. - php中引用的字符串

    如果您 然后,语法错误通常以后进行。

     ×
    回声“一些文本”,$ a_variable”和一些失控的字符串;
    成功(“完成”);
             ⇯
     

    当时解析器可能会抗议,这不仅是文字 t_string 。另一个频繁的变化是 意外'&gt;' 未引用的文字html。


  7. 如果您复制和粘贴代码从博客或网站上,有时您最终会得到无效的代码。 印刷报价不是 php期望的是什么:

      $ text ='某事..' +“这些不是引号”;
     

    印刷/智能引号是Unicode符号。 PHP将它们视为毗邻字母数字文本的一部分。例如,“这些被解释为常数标识符。但是,解析器将以下任何文字视为裸词/t_string。

  8. 缺失的半隆;再次

    如果您在以前的行中有未终止的表达式,则以下任何语句或语言构造被视为原始标识符:

     ×
    func1()
    函数2();
     

    php只是不知道您是否打算在另一个接一个地运行两个功能,或者是否要乘以它们的结果,添加它们,比较它们,或者仅运行一个 || 或另一个。

  9. 短打开标签和&lt;?xml php脚本中的标题

    这很少见。但是,如果启用了short_open_tags,则无法开始php脚本

     ×
    &lt;?xml版本=“ 1.0”?&gt;
     

    php将看到&lt;?并为其本身收回。它不会理解杂散 xml 的目的。它将被解释为恒定。但是版本将被视为另一个文字/常数。而且,由于没有表达式操作员之间的两个随后的文字/值无法理解,这将是解析器的失败。

  10. 隐形Unicode字符

    语法错误的最丑陋原因是Unicode符号,例如。 PHP允许Unicode字符作为标识符名称。如果您收到T_String解析器的完全不疑问的代码,例如:

     &lt;?php
        打印123;
     

    您需要打破另一个文本编辑器。甚至是六角形。这里看起来像普通的空间和新线,可能包含无形的常数。有时基于Java的IDE有时会忽略在内部固定的UTF-8 BOM,零宽的空间,段落分离器等。

    您可以在每行添加冗余; 语句分隔符中缩小范围:

     &lt;?php
        ;打印123;
     

    额外的; Semicolon在这里将将前面的不可见字符转换为未定义的常数参考(表达式为语句)。作为回报,PHP产生了有用的通知。

  11. ``$'''符号在变量名称前缺少

    php中的变量变量的名称。

    美元符号( $ )是将标识符标记为变量的名称。如果没有此sigil,标识符可以为a 语言关键字或a 常数

    当PHP代码为“翻译为用另一种语言的代码翻译”时,这是一个常见错误。 ,JavaScript等)。在这种情况下,变量类型的声明(当原始代码用使用键入变量的语言编写时)也可能会偷偷摸摸并产生此错误。


  12. 逃脱的引号

    如果您在字符串中使用 \ ,则具有特殊的含义。这称为“ 逃脱字符“从字面上看下一个角色。

    示例:回声'

    如果您逃脱了字符串的关闭报价,则将关闭的报价从字面上拿走,而不是按预期进行,即作为字符串的一部分而不是关闭字符串的可打印报价。打开下一个字符串或在脚本末尾,通常将其显示为解析错误。

    在Windows中指定路径时非常常见的错误:“ C:\ XAMPP \ htdocs \” 是错误的。您需要“ c:\\ xampp \\ htdocs \\”

  13. 键入属性

    您需要php≥7.4才能使用属性property property typing

      public stdclass $ obj;
     

Unexpected T_STRING

T_STRING is a bit of a misnomer. It does not refer to a quoted "string". It means a raw identifier was encountered. This can range from bare words to leftover CONSTANT or function names, forgotten unquoted strings, or any plain text.

  1. Misquoted strings

    This syntax error is most common for misquoted string values however. Any unescaped and stray " or ' quote will form an invalid expression:

                   ⇓                  ⇓
     echo "<a href="http://example.com">click here</a>";
    

    Syntax highlighting will make such mistakes super obvious. It's important to remember to use backslashes for escaping \" double quotes, or \' single quotes - depending on which was used as string enclosure.

    • For convenience you should prefer outer single quotes when outputting plain HTML with double quotes within.
    • Use double quoted strings if you want to interpolate variables, but then watch out for escaping literal " double quotes.
    • For lengthier output, prefer multiple echo/print lines instead of escaping in and out. Better yet consider a HEREDOC section.

    Another example is using PHP entry inside HTML code generated with PHP:

    $text = '<div>some text with <?php echo 'some php entry' ?></div>'
    

    This happens if $text is large with many lines and developer does not see the whole PHP variable value and focus on the piece of code forgetting about its source. Example is here

    See also What is the difference between single-quoted and double-quoted strings in PHP?.

  2. Unclosed strings

    If you miss a closing " then a syntax error typically materializes later. An unterminated string will often consume a bit of code until the next intended string value:

                                                           ⇓
    echo "Some text", $a_variable, "and some runaway string ;
    success("finished");
             ⇯
    

    It's not just literal T_STRINGs which the parser may protest then. Another frequent variation is an Unexpected '>' for unquoted literal HTML.

  3. Non-programming string quotes

    If you copy and paste code from a blog or website, you sometimes end up with invalid code. Typographic quotes aren't what PHP expects:

    $text = ’Something something..’ + ”these ain't quotes”;
    

    Typographic/smart quotes are Unicode symbols. PHP treats them as part of adjoining alphanumeric text. For example ”these is interpreted as a constant identifier. But any following text literal is then seen as a bareword/T_STRING by the parser.

  4. The missing semicolon; again

    If you have an unterminated expression in previous lines, then any following statement or language construct gets seen as raw identifier:

           ⇓
    func1()
    function2();
    

    PHP just can't know if you meant to run two functions after another, or if you meant to multiply their results, add them, compare them, or only run one || or the other.

  5. Short open tags and <?xml headers in PHP scripts

    This is rather uncommon. But if short_open_tags are enabled, then you can't begin your PHP scripts with an XML declaration:

          ⇓
    <?xml version="1.0"?>
    

    PHP will see the <? and reclaim it for itself. It won't understand what the stray xml was meant for. It'll get interpreted as constant. But the version will be seen as another literal/constant. And since the parser can't make sense of two subsequent literals/values without an expression operator in between, that'll be a parser failure.

  6. Invisible Unicode characters

    A most hideous cause for syntax errors are Unicode symbols, such as the non-breaking space. PHP allows Unicode characters as identifier names. If you get a T_STRING parser complaint for wholly unsuspicious code like:

    <?php
        print 123;
    

    You need to break out another text editor. Or an hexeditor even. What looks like plain spaces and newlines here, may contain invisible constants. Java-based IDEs are sometimes oblivious to an UTF-8 BOM mangled within, zero-width spaces, paragraph separators, etc. Try to reedit everything, remove whitespace and add normal spaces back in.

    You can narrow it down with with adding redundant ; statement separators at each line start:

    <?php
        ;print 123;
    

    The extra ; semicolon here will convert the preceding invisible character into an undefined constant reference (expression as statement). Which in return makes PHP produce a helpful notice.

  7. The `$` sign missing in front of variable names

    Variables in PHP are represented by a dollar sign followed by the name of the variable.

    The dollar sign ($) is a sigil that marks the identifier as a name of a variable. Without this sigil, the identifier could be a language keyword or a constant.

    This is a common error when the PHP code was "translated" from code written in another language (C, Java, JavaScript, etc.). In such cases, a declaration of the variable type (when the original code was written in a language that uses typed variables) could also sneak out and produce this error.

  8. Escaped Quotation marks

    If you use \ in a string, it has a special meaning. This is called an "Escape Character" and normally tells the parser to take the next character literally.

    Example: echo 'Jim said \'Hello\''; will print Jim said 'hello'

    If you escape the closing quote of a string, the closing quote will be taken literally and not as intended, i.e. as a printable quote as part of the string and not close the string. This will show as a parse error commonly after you open the next string or at the end of the script.

    Very common error when specifiying paths in Windows: "C:\xampp\htdocs\" is wrong. You need "C:\\xampp\\htdocs\\".

  9. Typed properties

    You need PHP ≥7.4 to use property typing such as:

    public stdClass $obj;
    
温柔戏命师 2025-02-02 07:37:39

意外

打开括号通常遵循语言构造,例如/ foreach / for / for / array 代码>/<代码>列表或启动算术表达式。 上下文中。

  1. > $ ,在某些典型的声明

    此错误的罕见发生是试图将表达式用作默认功能参数。即使在php7中也不支持这一点:

     函数header_fallback($ value,$ expires = time() + 90000){
     

    函数声明中的参数只能是文字值或常数表达式。与功能调用不同,您可以在其中自由使用 whything(1+theings()*2)等。

  2. 类成员声明允许文字/常数值,而不是表达式:

     类XYZ {
        var $ default = get_config(“ xyz_default”);
     

    将这样的东西放入构造函数中。
    另请参阅为什么PHP属性不允许函数?

    再次注意,PHP 7仅允许 var $ xy = 1 + 2 +3; 在那里的常数表达式。

  3. php

    中的JavaScript语法

    使用javascript或 jquery Syntax 出于明显的原因,在PHP中:

     &lt;?php
        打印$(document).text();
     

    发生这种情况时,通常表示前面的未终止的字符串;和文字&lt; script&gt; 插件泄漏到php代码上下文

  4. isset(()),空,键,下一个,当前

    isset() empty()是语言内置,而不是函数。他们 /a>。如果您无意中添加了一对括号,则可以创建一个表达式:

     ×
    if(isset(($ _ get [“ id”))){
     

    同样适用于任何需要隐式变量名称访问的语言构造。这些内置是语言语法的一部分,因此不允许装饰性额外的括号。

    导致运行时错误。

意外

  1. 缺乏功能参数

    您不能有流浪 commas> commas thas thes thes the函数调用。 PHP期望那里有一个价值,因此抱怨早期关闭括号。

     ×
    callfunc(1,2,);
     

    仅在 array()或 list()构造中允许tailing逗号。

  2. 未完成的表达式

    如果您忘记了算术表达中的某些东西,那么解析器就会放弃。因为它应该如何解释:

     ×
    $ var = 2 *(1 +);
     

    并且,如果您忘记了闭合,即使您会收到关于意外的半隆的抱怨。

  3. foreach as 常数

    对于 enpotter控制语句您会看到:

     ↓⇓
    foreach($ array作为错误){
     

    php这里有时会告诉您 :: 而不是。因为类:: $ variable可以满足预期的$变量表达式。

意外的 {

curly braces {} 封闭代码块。它们的语法错误通常表示一些不正确的嵌套。

  1. 中的无与伦比的子表达

    最常见的是不平衡 )() /code> 如果解析器抱怨开口卷曲 {出现得太早,则是原因。一个简单的例子:

     ×
    if(($ x == $ y)&amp;&amp;(2 == true){
     

    计算您的括号或使用IDE来帮助这一点。也不要在没有任何空间的情况下编写代码。可读性计数。

  2. {and}在表达式上下文中

    您不能在表达式中使用卷曲括号。如果您混淆括号和卷发,它将不符合语言语法:

     ×
    $ var = 5 * {7 + $ x};
     

    标识符构造有一些例外,例如本地范围变量 $ {core}

  3. 变量变量或卷曲var表达式

    这很少见。但是您也可能会得到 {} 复杂变量表达式的解析器投诉:

     ×
    打印“你好{$ world [2 {]}!”;
     

    尽管在这种情况下出现意外的} 的可能性更高。

出乎意料的}

获得“出乎意料的} ”错误时,您大多要过早关闭代码块。

  1. 代码块中的最后一个语句

    任何未终止的表达都可能发生。

    ,如果函数/代码块中的最后一行缺少尾声; semicolon:

     函数whything(){
        dostuff()
    }⇧
     

    在这里,解析器无法确定您是否仍然想将+ 25; 添加到函数结果或其他内容。

  2. 无效的块嵌套/忘记 {

    当代码块为} 关闭过早时,您有时会看到此解析器错误,或者您忘记了开放 {偶数:

     函数dostuff(){
        如果(true)⇦
            打印“是”;
        }
    }⇧
     

    在上面的摘要中,如果没有开口 { curly brace。因此,下面的关闭} 变得多余。因此,用于该功能的下一个关闭} 与原始开口 { curly brace。

    如果没有适当的代码缩进,就很难找到此类错误。使用IDE和括号匹配。

意外的 {,期望

语言构造需要条件/声明标题 代码块将触发此错误。

  1. 参数列表

    例如 misdeclared函数,没有参数列表 不允许:

     ×
    功能{
    }
     
  2. 控制语句条件

    ,您也不能同样拥有 if if 没有条件P>

     ×
    如果 {
    }
     

    显然没有意义。对于通常的嫌疑人来说,/ foreach , while / do

    如果您遇到了这个特定的错误,则绝对应该查找一些手动示例。

Unexpected (

Opening parentheses typically follow language constructs such as if/foreach/for/array/list or start an arithmetic expression. They're syntactically incorrect after "strings", a previous (), a lone $, and in some typical declaration contexts.

  1. Function declaration parameters

    A rarer occurrence for this error is trying to use expressions as default function parameters. This is not supported, even in PHP7:

    function header_fallback($value, $expires = time() + 90000) {
    

    Parameters in a function declaration can only be literal values or constant expressions. Unlike for function invocations, where you can freely use whatever(1+something()*2), etc.

  2. Class property defaults

    Same thing for class member declarations, where only literal/constant values are allowed, not expressions:

    class xyz {                   ⇓
        var $default = get_config("xyz_default");
    

    Put such things in the constructor.
    See also Why don't PHP attributes allow functions?

    Again note that PHP 7 only allows var $xy = 1 + 2 +3; constant expressions there.

  3. JavaScript syntax in PHP

    Using JavaScript or jQuery syntax won't work in PHP for obvious reasons:

    <?php      ⇓
        print $(document).text();
    

    When this happens, it usually indicates an unterminated preceding string; and literal <script> sections leaking into PHP code context.

  4. isset(()), empty, key, next, current

    Both isset() and empty() are language built-ins, not functions. They need to access a variable directly. If you inadvertently add a pair of parentheses too much, then you'd create an expression however:

              ⇓
    if (isset(($_GET["id"]))) {
    

    The same applies to any language construct that requires implicit variable name access. These built-ins are part of the language grammar, therefore don't permit decorative extra parentheses.

    User-level functions that require a variable reference -but get an expression result passed- lead to runtime errors instead.

Unexpected )

  1. Absent function parameter

    You cannot have stray commas last in a function call. PHP expects a value there and thusly complains about an early closing ) parenthesis.

                  ⇓
    callfunc(1, 2, );
    

    A trailing comma is only allowed in array() or list() constructs.

  2. Unfinished expressions

    If you forget something in an arithmetic expression, then the parser gives up. Because how should it possibly interpret that:

                   ⇓
    $var = 2 * (1 + );
    

    And if you forgot the closing ) even, then you'd get a complaint about the unexpected semicolon instead.

  3. Foreach as constant

    For forgotten variable $ prefixes in control statements you will see:

                       ↓    ⇓
    foreach ($array as wrong) {
    

    PHP here sometimes tells you it expected a :: instead. Because a class::$variable could have satisfied the expected $variable expression..

Unexpected {

Curly braces { and } enclose code blocks. And syntax errors about them usually indicate some incorrect nesting.

  1. Unmatched subexpressions in an if

    Most commonly unbalanced ( and ) are the cause if the parser complains about the opening curly { appearing too early. A simple example:

                                  ⇓
    if (($x == $y) && (2 == true) {
    

    Count your parentheses or use an IDE which helps with that. Also don't write code without any spaces. Readability counts.

  2. { and } in expression context

    You can't use curly braces in expressions. If you confuse parentheses and curlys, it won't comply to the language grammar:

               ⇓
    $var = 5 * {7 + $x};
    

    There are a few exceptions for identifier construction, such as local scope variable ${references}.

  3. Variable variables or curly var expressions

    This is pretty rare. But you might also get { and } parser complaints for complex variable expressions:

                          ⇓
    print "Hello {$world[2{]} !";
    

    Though there's a higher likelihood for an unexpected } in such contexts.

Unexpected }

When getting an "unexpected }" error, you've mostly closed a code block too early.

  1. Last statement in a code block

    It can happen for any unterminated expression.

    And if the last line in a function/code block lacks a trailing ; semicolon:

    function whatever() {
        doStuff()
    }            ⇧
    

    Here the parser can't tell if you perhaps still wanted to add + 25; to the function result or something else.

  2. Invalid block nesting / Forgotten {

    You'll sometimes see this parser error when a code block was } closed too early, or you forgot an opening { even:

    function doStuff() {
        if (true)    ⇦
            print "yes";
        }
    }   ⇧
    

    In above snippet the if didn't have an opening { curly brace. Thus the closing } one below became redundant. And therefore the next closing }, which was intended for the function, was not associable to the original opening { curly brace.

    Such errors are even harder to find without proper code indentation. Use an IDE and bracket matching.

Unexpected {, expecting (

Language constructs which require a condition/declaration header and a code block will trigger this error.

  1. Parameter lists

    For example misdeclared functions without parameter list are not permitted:

                     ⇓
    function whatever {
    }
    
  2. Control statement conditions

    And you can't likewise have an if without condition.

      ⇓
    if {
    }
    

    Which doesn't make sense, obviously. The same thing for the usual suspects, for/foreach, while/do, etc.

    If you've got this particular error, you definitely should look up some manual examples.

极致的悲 2025-02-02 07:37:39

意外的T_IF
意外的T_elseif
意外的T_ELSE
意外的T_ENDIF

条件控制块如果 elseif else 遵循简单的结构。当您遇到语法错误时,很可能只是无效的块嵌套→缺少 { curly braces } - 或一个太多。

  1. 缺少 {} 由于不正确的凹痕

    不匹配的代码括号对于较不符合良好的代码(例如:

    )是常见的

      if((!($ opt [“ uniqartz5.8”)!= $ this-&gt; check58))或(空($ _ post ['poree']))){如果
    ($ true){echo“ halp”;} elseif((!$ z)或%b){excsmthng(false,5.8)} elseif(false){
     

    如果您的代码看起来像这样,请重新开始!否则,它对您或其他任何人都无法混合。在Internet上展示此信息以寻求帮助是没有意义的。

    您只能在视觉上遵循嵌套的结构和IF/else条件及其 {代码块} 的关系。使用您的IDE查看它们是否都配对。

      if(true){
         if(false){
                  …
         }
         elseif($ whywath){
             if($ sosings2){
                 …
             } 
             别的 {
                 …
             }
         }
         别的 {
             …
         }
         if(false){//第二个`if`树
             …
         }
         别的 {
             …
         }
    }
    elseif(false){
        …
    }
     

    任何双重} } 不仅会关闭分支,而且将关闭先前的条件结构。因此坚持一种编码样式;如果/else树,请勿在嵌套中混合和匹配。

    除了一致性之外,事实证明,避免冗长的条件也有帮助。 避免不可读如果 expressions

  2. 如果无法在表达式中使用

    出人意料的新人错误是尝试使用语句在表达式中使用,例如打印语句:

     ×
    echo“&lt; a href ='”。如果($ link ==“ example.org”){echo…
     

    当然是无效的。

    您可以使用一个三元条件,请注意可读性影响。

      echo“&lt; a href ='”。 ($ link?“ http:// yes”:“ http:// no”)。 “&lt;/a&gt;“;
     

    否则否则会破坏这样的输出构造:使用多个如果 s和 echo s
    更好的是,请使用临时变量,然后将条件放置在:< /p>

      if($ link){$ href =“ yes”; } else {$ href =“ no”; }
    echo“&lt; a href ='$ href'&gt; link&lt;/a&gt;“;
     

    为这种情况定义功能或方法通常也很有意义。

    控制块不返回“结果”

    现在这不太常见,但是一些编码器甚至尝试处理,就好像它可以返回 result

      $ var = if($ x == $ y){“ true”};
     

    在字符串串联/表达式中使用在结构上与使用相同。

    • 但是控制结构(如果/foreach/while)没有“结果”
    • 字面字符串“ true”也只是一个无效的陈述。

    您必须在代码块中使用分配

      if($ x == $ y){$ var =“ true”; }
     

    或者,求助于?:三元比较。

    如果在if

    如果 < < < /a>在条件下:

     ×
    if($ x == true和(如果$ y!= false)){...}
     

    显然是多余的,因为(或)已经允许链接比较。

  3. 忘记; semicolons

    再次:每个控制块都需要是一个语句。如果先前的代码件未被半柱终止,则是保证的语法错误:

     ×
    $ var = 1 + 2 + 3
    如果(ture){…}
     

    btw, {…} 代码块中的最后一行也需要一个分号。

  4. 半隆

    现在可能要责怪特定的编码方式是错误的,因为这个陷阱太容易忽略了:

     ×
    如果($ x == 5);
    {
        $ y = 7;
    }
    否←
    {
        $ x = -1;    
    }
     

    发生的时间比您想象的要多。

    • 当您终止 if() ; 它将执行一个void语句。 ; 自己成为一个空的 {} 自己!
    • 因此, else 不再与 construct,
      这就是为什么这会导致意外的T_ELSE语法错误。

    还解释了此语法错误的微妙变化:

      if($ x){x_is_true(); }; else {sosings_else(); };
     

    ; 在代码块 {…} 之后终止整个如果
    切断 else 分支

  5. 不使用代码块

    句法允许省略卷曲括号 {} 中的代码块,如果/ elseif> elseif /<代码> else 分支。遗憾的是,这是一种无关编码器非常常见的语法样式。 (在错误的假设下,这更快地输入或读取)。

    但是,这很有可能会绊倒语法。迟早的其他语句将进入if/else分支:

     如果(true)
        $ x = 5;
    elseif(false)
        $ x = 6;
        $ y = 7; ←
    别的
        $ z = 0;
     

    但是,要实际使用代码块,您 确实有 {} 它们这样!

    即使经验丰富的程序员避免使用此无音句,或者至少
    将其理解为规则的例外。

  6. 其他 / elseif在错误的顺序< / h3>

    提醒自己的一件事是有条件的顺序当然。

      if($ a){…}
    别的 { … }
    elseif($ b){…}
    ↑
     

    您可以随意拥有尽可能多的 elseif s,但是 else 必须进行最后。就是这样。

  7. 类声明

    AS 上面提到的,您无法在类声明中具有控制语句:

     类xyz {
        if(true){
            功能($ var){}
        }
     

    您要么 t-finction> 下过早关闭一个}

  8. 意外的T_ELSEIF / T_ELSE < / h3>

    混合PHP和HTML时,的关闭} 如果/elseif 必须在相同的php块&lt;?php?&gt; 作为下一个 elseif/else 。如果> 需要成为 elseif

    ,这将产生错误::::

     &lt;?php if($ x){?&gt;
        html
    &lt;?php}?&gt;
    &lt;?
        html
    &lt;?php}?&gt;
     

    正确的表单&lt;?php} elseif

     &lt;?php if($ x){?&gt;
        html
    &lt;?php} elseif($ y){?&gt;
        html
    &lt;?php}?&gt;
     

    这或多或少是错误的压痕变化 - 大概是基于错误的编码意图。
    您不能 mash其他语句 如果和 elseif / else 结构令牌:

      if(true){
    }
    回声“之间”; ←
    elseif(false){
    }
    ?&gt;文本&lt;?php←
    别的 {
    }
     

    只能出现在 {…} 代码块中,而不是在控制结构令牌之间。

    • 无论如何,这都是没有意义的。当php在> 之间跳跃时,没有一些“未定义”状态, else branch。
    • 您必须下定决心,如果需要在两个分支中重复打印语句的地方。

    a if/else 在不同的控制结构之间:

      foreach($ array as $ i){
        如果($ i){…}
    }
    别的 { … }
     

    没有语法关系 之间否则。 结束,因此 结构可以继续。

  9. t_endif

    如果抱怨出乎意料的t_endif,则您正在使用替代语法样式 if: elseif: else:⋯<<< 代码> endif; 。您应该三思而后行。

    • A common pitfall is confusing the eerily

  10. 分配与比较

    因此,这不是语法错误,而是在这种情况下值得一提的:

     ×
    如果($ x = true){}
    else {do_false(); }
     

    不是 == // ================= 比较,但 = 分配。这是相当微妙的,很容易引导某些用户无助地编辑整个条件块。首先提防意外任务 - 当您遇到逻辑故障 /不良行为时。< / p>

Unexpected T_IF
Unexpected T_ELSEIF
Unexpected T_ELSE
Unexpected T_ENDIF

Conditional control blocks if, elseif and else follow a simple structure. When you encounter a syntax error, it's most likely just invalid block nesting → with missing { curly braces } - or one too many.

enter image description here

  1. Missing { or } due to incorrect indentation

    Mismatched code braces are common to less well-formatted code such as:

    if((!($opt["uniQartz5.8"]!=$this->check58)) or (empty($_POST['poree']))) {if
    ($true) {echo"halp";} elseif((!$z)or%b){excSmthng(False,5.8)}elseif (False){
    

    If your code looks like this, start afresh! Otherwise it's unfixable to you or anyone else. There's no point in showcasing this on the internet to inquire for help.

    You will only be able to fix it, if you can visually follow the nested structure and relation of if/else conditionals and their { code blocks }. Use your IDE to see if they're all paired.

    if (true) {
         if (false) {
                  …
         }
         elseif ($whatever) {
             if ($something2) {
                 …
             } 
             else {
                 …
             }
         }
         else {
             …
         }
         if (false) {    //   a second `if` tree
             …
         }
         else {
             …
         }
    }
    elseif (false) {
        …
    }
    

    Any double } } will not just close a branch, but a previous condition structure. Therefore stick with one coding style; don't mix and match in nested if/else trees.

    Apart from consistency here, it turns out helpful to avoid lengthy conditions too. Use temporary variables or functions to avoid unreadable if-expressions.

  2. IF cannot be used in expressions

    A surprisingly frequent newcomer mistake is trying to use an if statement in an expression, such as a print statement:

                       ⇓
    echo "<a href='" . if ($link == "example.org") { echo …
    

    Which is invalid of course.

    You can use a ternary conditional, but beware of readability impacts.

    echo "<a href='" . ($link ? "http://yes" : "http://no") . "</a>";
    

    Otherwise break such output constructs up: use multiple ifs and echos.
    Better yet, use temporary variables, and place your conditionals before:

    if ($link) { $href = "yes"; } else { $href = "no"; }
    echo "<a href='$href'>Link</a>";
    

    Defining functions or methods for such cases often makes sense too.

    Control blocks don't return "results"

    Now this is less common, but a few coders even try to treat if as if it could return a result:

    $var = if ($x == $y) { "true" };
    

    Which is structurally identical to using if within a string concatenation / expression.

    • But control structures (if / foreach / while) don't have a "result".
    • The literal string "true" would also just be a void statement.

    You'll have to use an assignment in the code block:

    if ($x == $y) { $var = "true"; }
    

    Alternatively, resort to a ?: ternary comparison.

    If in If

    You cannot nest an if within a condition either:

                        ⇓
    if ($x == true and (if $y != false)) { ... }
    

    Which is obviously redundant, because the and (or or) already allows chaining comparisons.

  3. Forgotten ; semicolons

    Once more: Each control block needs to be a statement. If the previous code piece isn't terminated by a semicolon, then that's a guaranteed syntax error:

                    ⇓
    $var = 1 + 2 + 3
    if (true) { … }
    

    Btw, the last line in a {…} code block needs a semicolon too.

  4. Semicolon too early

    Now it's probably wrong to blame a particular coding style, as this pitfall is too easy to overlook:

                ⇓
    if ($x == 5);
    {
        $y = 7;
    }
    else           ←
    {
        $x = -1;    
    }
    

    Which happens more often than you might imagine.

    • When you terminate the if () expression with ; it will execute a void statement. The ; becomes a an empty {} of its own!
    • The {…} block thus is detached from the if, and would always run.
    • So the else no longer had a relation to an open if construct,
      which is why this would lead to an Unexpected T_ELSE syntax error.

    Which also explains a likewise subtle variation of this syntax error:

    if ($x) { x_is_true(); }; else { something_else(); };
    

    Where the ; after the code block {…} terminates the whole if
    construct, severing the else branch syntactically.

  5. Not using code blocks

    It's syntactically allowed to omit curly braces {} for code blocks in if/elseif/else branches. Which sadly is a syntax style very common to unversed coders. (Under the false assumption this was quicker to type or read).

    However that's highly likely to trip up the syntax. Sooner or later additional statements will find their way into the if/else branches:

    if (true)
        $x = 5;
    elseif (false)
        $x = 6;
        $y = 7;     ←
    else
        $z = 0;
    

    But to actually use code blocks, you do have to write {} them as such!

    Even seasoned programmers avoid this braceless syntax, or at least
    understand it as an exceptional exception to the rule.

  6. Else / Elseif in wrong order

    One thing to remind yourself is the conditional order, of course.

    if ($a) { … }
    else { … }
    elseif ($b) { … }
    ↑
    

    You can have as many elseifs as you want, but else has to go last. That's just how it is.

  7. Class declarations

    As mentioned above, you can't have control statements in a class declaration:

    class xyz {
        if (true) {
            function ($var) {}
        }
    

    You either forgot a function definition, or closed one } too early in such cases.

  8. Unexpected T_ELSEIF / T_ELSE

    When mixing PHP and HTML, the closing } for an if/elseif must be in the same PHP block <?php ?> as the next elseif/else. This will generate an error as the closing } for the if needs to be part of the elseif:

    <?php if ($x) { ?>
        html
    <?php } ?>
    <?php elseif ($y) { ?>
        html
    <?php } ?>
    

    The correct form <?php } elseif:

    <?php if ($x) { ?>
        html
    <?php } elseif ($y) { ?>
        html
    <?php } ?>
    

    This is more or less a variation of incorrect indentation - presumably often based on wrong coding intentions.
    You cannot mash other statements inbetween if and elseif/else structural tokens:

    if (true) {
    }
    echo "in between";    ←
    elseif (false) {
    }
    ?> text <?php      ←
    else {
    }
    

    Either can only occur in {…} code blocks, not in between control structure tokens.

    • This wouldn't make sense anyway. It's not like that there was some "undefined" state when PHP jumps between if and else branches.
    • You'll have to make up your mind where print statements belong to / or if they need to be repeated in both branches.

    Nor can you part an if/else between different control structures:

    foreach ($array as $i) {
        if ($i) { … }
    }
    else { … }
    

    There is no syntactic relation between the if and else. The foreach lexical scope ends at }, so there's no point for the if structure to continue.

  9. T_ENDIF

    If an unexpected T_ENDIF is complained about, you're using the alternative syntax style if:elseif:else:endif;. Which you should really think twice about.

    • A common pitfall is confusing the eerily similar : colon for a ; semicolon. (Covered in "Semicolon too early")

    • As indentation is harder to track in template files, the more when using the alternative syntax - it's plausible your endif; does not match any if:.

    • Using } endif;
      is a doubled if-terminator.

    While an "unexpected $end" is usually the price for a forgotten closing } curly brace.

  10. Assignment vs. comparison

    So, this is not a syntax error, but worth mentioning in this context:

           ⇓
    if ($x = true) { }
    else { do_false(); }
    

    That's not a ==/=== comparison, but an = assignment. This is rather subtle, and will easily lead some users to helplessly edit whole condition blocks. Watch out for unintended assignments first - whenver you experience a logic fault / misbeheviour.

葬花如无物 2025-02-02 07:37:39

出乎意料的$结束

时,当PHP谈论“意外 $ end ”时,这意味着您的代码在解析器期望更多的代码时结束。 (从字面上获取时,该消息有点误导。它与新移民有时假设的变量无关。它指的是“文件的结尾”, eof 。)。

原因:不平衡 { and } for Code Blocks/and function或Class声明。

关于缺少的} 卷曲支架几乎总是 ,以关闭前面的代码块。这是解析器期望找到关闭的} ,但实际上达到了文件的末尾。

  • 再次使用适当的凹痕避免此类问题。

  • 使用与括号匹配的IDE,以找出} 不对劲的位置。
    大多数IDE和文本编辑器中都有键盘快捷键:

    • netbeans,phpstorm,komodo: ctrl [ ctrl ] ]
    • eclipse,aptana: ctrl shift p
    • atom,sublime: ctrl m - Zend Studio ctrl m m
    • geany,记事本++: ctrl b -Joe: ctrl gbd> g g - /kbd> - vim:

大多数IDE也 ive 突出显示匹配的支架,支架和括号。
这使得检查其相关性非常容易:

“在IDE中匹配的括号”

未终止的表达式

意外$ end $ end $ end 语法/解析器错误也可能发生未终止的表达式或语句:

  • $ var = func(1,
    ?&gt; eof

首先查看脚本的结尾。在任何PHP脚本中的最后一个语句中,尾随; 通常是多余的。但是您应该有一个。正是因为它缩小了这种语法问题。特别是在您发现自己在脚本末尾添加更多语句之后。

缩进的Heredoc Markers

另一个常见发生出现,出现字符串。终止标记物被领先的空间,选项卡等忽略:

print <<< END
    Content...
    Content....
  END;
# ↑ terminator isn't exactly at the line start

因此,解析器假设Heredoc字符串继续进行直到文件结束(因此“意外$ end”)。几乎所有的IDE和语法高音编辑都将使这一明显或警告。

ESC的引号标记

如果您在字符串中使用 \ ,则具有特殊的含义。这称为“ 逃脱字符“从字面上看下一个角色。

回声'

示例: 从字面上看,不是预期的,即作为字符串的一部分而不是关闭字符串的可打印报价。在打开下一个字符串或脚本末尾之后,通常会显示为解析错误。

在Windows中指定路径时非常常见的错误:“ C:\ XAMPP \ HTDOCS \” 是错误的。您需要“ c:\\ xampp \\ htdocs \\” 。另外,PHP通常会将Unix风格的路径(例如“ C:/XAMPP/HTDOCS/” )转换为Windows的正确路径。

替代语法

在某种程度上有些稀有,您可以在模板中使用替代语法/代码块时看到此语法错误。使用 if:和 else:以及缺少的 endif;

另请参见:

Unexpected $end

When PHP talks about an "unexpected $end", it means that your code ended while the parser is expecting more code. (The message is a bit misleading when taken literally. It's not about a variable named "$end", as sometimes assumed by newcomers. It refers to the "end of file", EOF.)

Cause: Unbalanced { and } for code blocks / and function or class declarations.

It's pretty much always about a missing } curly brace to close preceding code blocks. What it's saying is that the parser is expecting to find a closing } but actually reached the end of the file.

  • Again, use proper indentation to avoid such issues.

  • Use an IDE with bracket matching, to find out where the } is amiss.
    There are keyboard shortcuts in most IDEs and text editors:

    • NetBeans, PhpStorm, Komodo: Ctrl[ and Ctrl]
    • Eclipse, Aptana: CtrlShiftP
    • Atom, Sublime: Ctrlm - Zend Studio CtrlM
    • Geany, Notepad++: CtrlB - Joe: CtrlG - Emacs: C-M-n - Vim: %

Most IDEs also highlight matching braces, brackets and parentheses.
Which makes it pretty easy to inspect their correlation:

Bracket matching in an IDE

Unterminated expressions

An Unexpected $end syntax/parser error can also occur for unterminated expressions or statements:

  • $var = func(1,
    ?>EOF

So, look at the end of scripts first. A trailing ; is often redundant for the last statement in any PHP script. But you should have one. Precisely because it narrows such syntax issues down. Particularly after you find yourself adding more statements at the end of the script.

Indented HEREDOC markers

Another common occurrence appears with HEREDOC or NOWDOC strings. The terminating marker goes ignored with leading spaces, tabs, etc.:

print <<< END
    Content...
    Content....
  END;
# ↑ terminator isn't exactly at the line start

Therefore the parser assumes the HEREDOC string to continue until the end of the file (hence "Unexpected $end"). Pretty much all IDEs and syntax-highlighting editors will make this obvious or warn about it.

Escaped Quotation marks

If you use \ in a string, it has a special meaning. This is called an "Escape Character" and normally tells the parser to take the next character literally.

Example: echo 'Jim said \'Hello\''; will print Jim said 'hello'

If you escape the closing quote of a string, the closing quote will be taken literally and not as intended, i.e. as a printable quote as part of the string and not close the string. This will show as a parse error commonly after you open the next string or at the end of the script.

Very common error when specifying paths in Windows: "C:\xampp\htdocs\" is wrong. You need "C:\\xampp\\htdocs\\". Alternately, PHP will usually convert Unix-style paths (e.g. "C:/xampp/htdocs/") to the correct path for Windows.

Alternative syntax

Somewhat rarer you can see this syntax error when using the alternative syntax for statement/code blocks in templates. Using if: and else: and a missing endif; for example.

See also:

辞旧 2025-02-02 07:37:39

意外的t_is_equal
意外的T_is_greater_or_equal
意外的t_is_istinal
意外的T_IS_NOT_EQUAL
意外的t_is_not_istinal
意外的T_is_smaller_or_equal
意外&lt;
意外&gt;

比较运算符,例如 == &gt; = ==== != ,,&lt ;应仅在表达式中使用,例如表达式。如果解析器对它们抱怨,则通常意味着围绕它们周围的parens parens不正确的削皮或不匹配的 )。

  1. Parens分组

    特别是,如果带有多个比较的语句,则必须注意正确计数开放和关闭括号

     ×
    if(($ foo&lt; 7)&amp;&amp; $ bar)&gt; 5 || $ baz&lt; 9){...}
                          ↑
     

    这里的如果条件已经由终止)

    您的比较变得足够复杂,如果构造而不是

  2. Isset()与比较

    捣碎

    一个普通的新人是pitfal试图结合 iSSET() 或< a href =“ http://php.net/empty” rel =“ nofollow noreferrer”> empty() 与比较:

     ×
    if(占($ _ post [“ var”] == 1)){
     

    甚至:

     ×
    if(isset($ variable!==“ value”)){
     

    这对PHP没有意义,因为 isset empty 是仅接受变量名称的语言构造。比较结果也没有意义,因为输出仅是/已经是布尔值。

  3. 混淆&gt; = 更大或平等与 =&gt; 数组operator

    两个操作员看起来有些相似,因此有时会混在一起:

     ×
    如果($ var =&gt; 5){...}
     

    您只需要记住,该比较操作员被称为“ 大于等于”才能正确。

    另请参见: if语句结构中的php

  4. 没有任何比较>

    ,如果它们与相同的变量名称相关,则您也无法结合两个比较:

     ×
    if($ xyz&gt; 5 and&lt; 100)
     

    PHP无法推断出您打算再次比较初始变量。表达通常根据操作员优先 &lt; 可以看到原始变量只剩下布尔结果。

    另请参阅:意外的t_is_smaller_or_equal

  5. 比较链

    您无法将变量与一排运算符进行比较:

     ×
     $ reult =(5&lt; $ x&lt; 10);
     

    这必须分解为两个比较,每个比较都与 $ x

    这实际上是黑名单表达式的情况(由于等效运算符协会)。它在几种C风格的语言中在语法上有效,但是PHP也不会将其解释为预期的比较链。

  6. 意外&gt;
    意外的&lt;

    大于&gt; 或小于&lt; 运营商没有自定义 t_xxx tokenizer name。虽然它们像其他所有人一样被放错了位置,但您经常看到解析器抱怨它们的字符串和捣碎的HTML:

     ×
    打印“&lt; a href ='z”&gt; hello&lt;/a&gt;“;
                     ↑
     

    这相当于字符串“&lt; a href ='z” 被比较&gt; 与字面的常数 Hello ,然后是另一个&lt; 比较。或者至少是PHP的看法。实际原因和语法错误是“ 终止”。

    也无法嵌套php启动标签:

     &lt;?php echo&lt;?php my_func(); ?&gt;
               ↑
     

另请参阅:

Unexpected T_IS_EQUAL
Unexpected T_IS_GREATER_OR_EQUAL
Unexpected T_IS_IDENTICAL
Unexpected T_IS_NOT_EQUAL
Unexpected T_IS_NOT_IDENTICAL
Unexpected T_IS_SMALLER_OR_EQUAL
Unexpected <
Unexpected >

Comparison operators such as ==, >=, ===, !=, <>, !== and <= or < and > mostly should be used just in expressions, such as if expressions. If the parser complains about them, then it often means incorrect paring or mismatched ( ) parens around them.

  1. Parens grouping

    In particular for if statements with multiple comparisons you must take care to correctly count opening and closing parenthesis:

                            ⇓
    if (($foo < 7) && $bar) > 5 || $baz < 9) { ... }
                          ↑
    

    Here the if condition here was already terminated by the )

    Once your comparisons become sufficiently complex it often helps to split it up into multiple and nested if constructs rather.

  2. isset() mashed with comparing

    A common newcomer is pitfal is trying to combine isset() or empty() with comparisons:

                            ⇓
    if (empty($_POST["var"] == 1)) {
    

    Or even:

                        ⇓
    if (isset($variable !== "value")) {
    

    This doesn't make sense to PHP, because isset and empty are language constructs that only accept variable names. It doesn't make sense to compare the result either, because the output is only/already a boolean.

  3. Confusing >= greater-or-equal with => array operator

    Both operators look somewhat similar, so they sometimes get mixed up:

             ⇓
    if ($var => 5) { ... }
    

    You only need to remember that this comparison operator is called "greater than or equal" to get it right.

    See also: If statement structure in PHP

  4. Nothing to compare against

    You also can't combine two comparisons if they pertain the same variable name:

                     ⇓
    if ($xyz > 5 and < 100)
    

    PHP can't deduce that you meant to compare the initial variable again. Expressions are usually paired according to operator precedence, so by the time the < is seen, there'd be only a boolean result left from the original variable.

    See also: unexpected T_IS_SMALLER_OR_EQUAL

  5. Comparison chains

    You can't compare against a variable with a row of operators:

                      ⇓
     $reult = (5 < $x < 10);
    

    This has to be broken up into two comparisons, each against $x.

    This is actually more a case of blacklisted expressions (due to equivalent operator associativity). It's syntactically valid in a few C-style languages, but PHP wouldn't interpret it as expected comparison chain either.

  6. Unexpected >
    Unexpected <

    The greater than > or less than < operators don't have a custom T_XXX tokenizer name. And while they can be misplaced like all they others, you more often see the parser complain about them for misquoted strings and mashed HTML:

                            ⇓
    print "<a href='z">Hello</a>";
                     ↑
    

    This amounts to a string "<a href='z" being compared > to a literal constant Hello and then another < comparison. Or that's at least how PHP sees it. The actual cause and syntax mistake was the premature string " termination.

    It's also not possible to nest PHP start tags:

    <?php echo <?php my_func(); ?>
               ↑
    

See also:

盛夏已如深秋| 2025-02-02 07:37:39

意外的T_IF
意外的T_foreach
出乎意料的t_for
意外的T_时
意外的T_DO
意外的T_echo

控制构造,例如,,, for , while ,, list ,<代码>全局,<代码>返回,<代码> do , print echo 只能用作语句。他们通常自己居住在一条线上。

  1. semicolon;你在哪里?

    非常普遍地让您错过了一个半元素如果解析器抱怨,则在上一行中关于控制语句:

     ×
    $ x = myfunc()
    if(true){
     

    解决方案:查看上一行;添加分号。

  2. 类声明

    发生这种情况的另一个位置是班级声明。在课程部分中,您只能列出属性初始化和方法部分。没有代码可以存放在那里。

     类xyz {
        如果(true){}
        foreach($ var){}
     

    这种语法错误通常是错误嵌套的 {} 的实现。特别是当功能代码块过早关闭时。

  3. 表达式上下文中的语句

    大多数语言构造都可以仅用用作语句 。它们并不是要放置在其他表达式中:

     ×
    $ var = array(1,2,foreach($ else as $ _),5,6);
     

    同样,如果在字符串,数学表达式或其他地方使用,也不能使用

     ×
    打印“哦”。如果(ture){“你!” }。 “行不通”;
    //当精通时,请在这里使用三元条件。
     

    用于嵌入类似于表达式中的条件,您经常想使用 ?:三元评估

    ,,, global , echo 和较小的扩展 list列表, 同样适用于, 。

     ×
    Echo 123,Echo 567,“嗯?”;
     

    print()是一种内置的语言,可以在表达式上下文中使用。 (但很少有意义。)

  4. 保留的关键字作为标识符

    如果 以及用户定义的函数或类名称的其他语言构造,您也不能使用或。 (也许在php&nbsp; 7中。但即使那样也不建议。)


  5. 您的控制块后,您有一个半彩色,而不是结肠(:)或curly bracket(:)或curly bracket({){)

    控制结构通常包裹在卷曲括号中(但结肠可以在替代语法)表示其范围。如果您不小心使用半彩色,则过早地关闭该块,导致您的关闭语句抛出错误。

    foreach ($errors as $error); <-- should be : or {

Unexpected T_IF
Unexpected T_FOREACH
Unexpected T_FOR
Unexpected T_WHILE
Unexpected T_DO
Unexpected T_ECHO

Control constructs such as if, foreach, for, while, list, global, return, do, print, echo may only be used as statements. They usually reside on a line by themselves.

  1. Semicolon; where you at?

    Pretty universally have you missed a semicolon in the previous line if the parser complains about a control statement:

                 ⇓
    $x = myfunc()
    if (true) {
    

    Solution: look into the previous line; add semicolon.

  2. Class declarations

    Another location where this occurs is in class declarations. In the class section you can only list property initializations and method sections. No code may reside there.

    class xyz {
        if (true) {}
        foreach ($var) {}
    

    Such syntax errors commonly materialize for incorrectly nested { and }. In particular when function code blocks got closed too early.

  3. Statements in expression context

    Most language constructs can only be used as statements. They aren't meant to be placed inside other expressions:

                       ⇓
    $var = array(1, 2, foreach($else as $_), 5, 6);
    

    Likewise can't you use an if in strings, math expressions or elsewhere:

                   ⇓
    print "Oh, " . if (true) { "you!" } . " won't work";
    // Use a ternary condition here instead, when versed enough.
    

    For embedding if-like conditions in an expression specifically, you often want to use a ?: ternary evaluation.

    The same applies to for, while, global, echo and a lesser extend list.

              ⇓
    echo 123, echo 567, "huh?";
    

    Whereas print() is a language built-in that may be used in expression context. (But rarely makes sense.)

  4. Reserved keywords as identifiers

    You also can't use do or if and other language constructs for user-defined functions or class names. (Perhaps in PHP 7. But even then it wouldn't be advisable.)

  5. Your have a semi-colon instead of a colon (:) or curly bracket ({) after your control block

    Control structures are typically wrapped in curly braces (but colons can be used in an alternative syntax) to represent their scope. If you accidentally use a semi-colon you prematurely close that block resulting in your closing statement throwing an error.

    foreach ($errors as $error); <-- should be : or {
无名指的心愿 2025-02-02 07:37:39

意外的?''

如果您尝试在&lt;?php 中使用&lt;?php ,则将给出此错误。

$var = 'hello '<?php echo 'world'; ?>;

*用于PHP版本4.3.1、4.3.5-4.3.11、4.4.0-4.4.1、5.0.0-5.0.5、4.4.4.2-4.4.2-4.4.9、5.1.0-5.1.0-5.1.6 ,5.2.0-5.2.17,5.3.0-5.3.29,5.4.0-5.4.45,5.5.0-5.5.38,5.6.0-5.6.40,7.0.0.0.0.0-7.0.0.33,7.1 .0-7.1.33,7.2.0-7.2.34,7.3.0-7.3.31,7.4.0-7.4.4-7.4.24


如果您试图使用null ColeScing Operator ?? < /代码>在PHP 7之前的PHP版本中,您将获得此错误。

<?= $a ?? 2; // works in PHP 7+
<?= (!empty($a)) ? $a : 2; // All versions of PHP

出乎意料的“?”,期望变量

对于无效类型可能会出现类似的错误,如:

function add(?int $sum): ?int {

再次指示正在使用过时的PHP版本(CLI版本 php -v -v 或WebServer BOND ANE BOND ANE phpinfo(); )。

Unexpected '?'

If you are trying to use <?php within <?php this error will be given*.

$var = 'hello '<?php echo 'world'; ?>;

* For PHP versions 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5, 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.31, 7.4.0 - 7.4.24


If you are trying to use the null coalescing operator ?? in a version of PHP prior to PHP 7 you will get this error.

<?= $a ?? 2; // works in PHP 7+
<?= (!empty($a)) ? $a : 2; // All versions of PHP

Unexpected '?', expecting variable

A similar error can occur for nullable types, as in:

function add(?int $sum): ?int {

Which again indicates an outdated PHP version being used (either the CLI version php -v or the webserver bound one phpinfo();).

俯瞰星空 2025-02-02 07:37:39

意外的t_lnumber

令牌 t_lnumber < / code>是指“长” /编号。

  1. 无效的变量名称

    在php和大多数其他编程语言中,不能以一个数字开头。第一个字符必须是字母或下划线。

      $ 1 //坏
    $ _1 //好
     

    “*”


    • 经常出现用于使用 preg_replace -placeholder “ $ 1” 在PHP上下文中:

       ##募定
      preg_replace(“/#(\ w+)/e”,strtopupper($ 1))
       

      应该引用回调的地方。 (现在已弃用了/e REGEX标志。

    • 相同的标识符约束适用于对象属性,btw。

       ↓
      $ json-&gt; 0-&gt; value
       
    • 虽然令牌/解析器不允许文字 $ 1 作为变量名称,但一个可以 使用 $ {1} $ {“ 1”} 。这是非标准标识符的句法解决方法。 (最好将其视为本地示波器查找。但是通常:在这种情况下更喜欢普通阵列!)

    • 有趣的是,但不推荐使用,PHPS解析器允许Unicode-sidentifiers;因此 $➊是有效的。 (与文字 1 不同)。

  2. 流浪阵列条目

    Array声明也可能发生意外的长时间。 - 缺少逗号:

     <代码>#↓↓
    $ xy = array(1 2 3);
     

    或同样的函数调用和声明以及其他构造:

    • func(1,2 3);
    • 函数xy($ z 2);
    • ($ i = 2 3&lt; $ z)

    因此,通常有一个; 或,用于分离列表或表达式的缺少。

  3. 错误引用的HTML

    再次,误引用的字符串数字:

     <代码>#↓↓          
    echo“&lt; td colspan =“ 3”&gt; ded&lt;/td&gt;“;
     

    这种情况应或多或少地像出乎意料的T_STRING 错误错误。

  4. 其他标识符

    既不函数,类,也不是可以以一个数字开始命名:

     ↓
    功能123shop(){
     

    与变量名称几乎相同。

Unexpected T_LNUMBER

The token T_LNUMBER refers to a "long" / number.

  1. Invalid variable names

    In PHP, and most other programming languages, variables cannot start with a number. The first character must be alphabetic or an underscore.

    $1   // Bad
    $_1  // Good
    

    *

    • Quite often comes up for using preg_replace-placeholders "$1" in PHP context:

      #                         ↓            ⇓  ↓
      preg_replace("/#(\w+)/e",  strtopupper($1) )
      

      Where the callback should have been quoted. (Now the /e regex flag has been deprecated. But it's sometimes still misused in preg_replace_callback functions.)

    • The same identifier constraint applies to object properties, btw.

             ↓
      $json->0->value
      
    • While the tokenizer/parser does not allow a literal $1 as variable name, one could use ${1} or ${"1"}. Which is a syntactic workaround for non-standard identifiers. (It's best to think of it as a local scope lookup. But generally: prefer plain arrays for such cases!)

    • Amusingly, but very much not recommended, PHPs parser allows Unicode-identifiers; such that $➊ would be valid. (Unlike a literal 1).

  2. Stray array entry

    An unexpected long can also occur for array declarations - when missing , commas:

    #            ↓ ↓
    $xy = array(1 2 3);
    

    Or likewise function calls and declarations, and other constructs:

    • func(1, 2 3);
    • function xy($z 2);
    • for ($i=2 3<$z)

    So usually there's one of ; or , missing for separating lists or expressions.

  3. Misquoted HTML

    And again, misquoted strings are a frequent source of stray numbers:

    #                 ↓ ↓          
    echo "<td colspan="3">something bad</td>";
    

    Such cases should be treated more or less like Unexpected T_STRING errors.

  4. Other identifiers

    Neither functions, classes, nor namespaces can be named beginning with a number either:

             ↓
    function 123shop() {
    

    Pretty much the same as for variable names.

水水月牙 2025-02-02 07:37:39

意外'='

这可能是由于在变量名称中具有无效的字符而引起的。变量名称​​必须遵循以下规则:

变量名称遵循与PHP中其他标签相同的规则。有效的变量名称以字母或下划线开头,然后是任何数量的字母,数字或下划线。作为正则表达式,它将被表达为:'[a-za-z \ x7f- \ xff] [a-za-z0-9_ \ x7f- \ xff]*'

Unexpected '='

This can be caused by having invalid characters in a variable name. Variables names must follow these rules:

Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'

柠檬 2025-02-02 07:37:39

意外的“最终”(t_endile)

语法正在使用结肠 - 如果没有结肠,则会发生上述错误。

<?php while($query->fetch()): ?>
 ....
<?php endwhile; ?>

该语法的替代方法是使用卷曲括号:

<?php while($query->fetch()) { ?>
  ....
<?php } ?>

http:/ http://php.net/手动/en/en-control structures.while.php

Unexpected 'endwhile' (T_ENDWHILE)

The syntax is using a colon - if there is no colon the above error will occur.

<?php while($query->fetch()): ?>
 ....
<?php endwhile; ?>

The alternative to this syntax is using curly brackets:

<?php while($query->fetch()) { ?>
  ....
<?php } ?>

http://php.net/manual/en/control-structures.while.php

伴随着你 2025-02-02 07:37:39

出乎意料的'。

如果您尝试使用 splat Operator( ... 不支持的PHP版本。

... 首先在PHP 5.6中可用,以捕获一个函数的可变数量参数:

function concatenate($transform, ...$strings) {
    $string = '';
    foreach($strings as $piece) {
        $string .= $piece;
    }
    return($transform($string));
}

echo concatenate("strtoupper", "I'd ", "like ", 4 + 2, " apples");
// This would print:
// I'D LIKE 6 APPLES

在PHP 7.4中,您可以将其用于 array表达式

$parts = ['apple', 'pear'];
$fruits = ['banana', 'orange', ...$parts, 'watermelon'];
// ['banana', 'orange', 'apple', 'pear', 'watermelon'];

Unexpected '.'

This can occur if you are trying to use the splat operator(...) in an unsupported version of PHP.

... first became available in PHP 5.6 to capture a variable number of arguments to a function:

function concatenate($transform, ...$strings) {
    $string = '';
    foreach($strings as $piece) {
        $string .= $piece;
    }
    return($transform($string));
}

echo concatenate("strtoupper", "I'd ", "like ", 4 + 2, " apples");
// This would print:
// I'D LIKE 6 APPLES

In PHP 7.4, you could use it for Array expressions.

$parts = ['apple', 'pear'];
$fruits = ['banana', 'orange', ...$parts, 'watermelon'];
// ['banana', 'orange', 'apple', 'pear', 'watermelon'];
戏舞 2025-02-02 07:37:39

意外

1。PHP8名称参数语法

意外':',期望','或')'

如果在PHP&lt版本中使用PHP 8的新名称参数功能; 8此错误将发生:

$table->string(column:'Name');

解决方案:

  1. 将您的PHP版本升级到PHP 8.0.0或更高版本,
  2. 请勿使用命名参数(以预期的顺序传递参数)

2。 :: 分隔符

开始解析错误的错误消息:语法错误,意外':'可能是通过错误地编写类静态参考 class :: $ variable as 类而引起的。 $变量

Unexpected :

1. PHP 8 named parameter syntax

unexpected ':', expecting ',' or ')'

If attempting to use PHP 8's new named parameter functionality in a version of PHP < 8 this error will occur:

$table->string(column:'Name');

Solutions:

  1. Upgrade your version of PHP to PHP 8.0.0 or higher
  2. Do not use named parameters (pass the parameters in the order they are expected)

2. Cropped class :: separator

An error message that begins Parse error: syntax error, unexpected ':' can be caused by mistakenly writing a class static reference Class::$Variable as Class:$Variable.

夜清冷一曲。 2025-02-02 07:37:39

意外的“继续”(t_continue)

继续是一个语句(例如,或者),并且必须独立出现。它不能用作表达的一部分。部分是因为继续返回值,但是在表达式中,每个子表达都必须导致某种值,因此总体表达式会导致值。这就是陈述和表达式之间的区别。

这意味着继续不能在三元语句或任何需要返回值的语句中使用。

出乎意料的“断裂”(t_break)

也是 Break; 当然也是如此。它在表达上下文中也不是可用的,而是严格的语句(在 block的同一级别上)。

意外的“返回”(t_return)

现在对于返回来说可能更令人惊讶,但这也只是一个块级语句。它确实将值(或null)返回到更高的范围/函数中,但不会评估为表达式本身。 →那就是:做 return(return(false);;

Unexpected 'continue' (T_CONTINUE)

continue is a statement (like for, or if) and must appear standalone. It cannot be used as part of an expression. Partly because continue doesn't return a value, but in an expression every sub-expression must result in some value so the overall expression results in a value. That's the difference between a statement and an expression.

That means continue cannot be used in a ternary statement or any statement that requires a return value.

Unexpected 'break' (T_BREAK)

Same goes for break; of course. It's also not usable in expression context, but a strict statement (on the same level as foreach or an if block).

Unexpected 'return' (T_RETURN)

Now this might be more surprising for return, but that's also just a block-level statement. It does return a value (or NULL) to the higher scope/function, but it does not evaluate as expression itself. → That is: there's no point in doing return(return(false);;

可爱咩 2025-02-02 07:37:39

发生这些错误的另一个原因是像带有代码的类似字符一样出乎意料的空格,代码行似乎是完美的,但是它们包含一些类似于Break Line或Whitespace或Whitespace或Tab的特定字符解析器。
当我尝试通过简单地复制粘贴将一些代码从网页中放置到代码编辑器时,我会面临这个问题,我看到了带有数组定义的错误。在数组定义中,一切都看起来正确。我无法整理正确的错误,最后我将此数组定义为单行,然后错误就消失了。然后,我再次尝试使该定义多个类似,但要手动为每个数组元素添加休息(Enter),并保存了该文件,这次没有编辑器解析错误,也没有错误的错误。
例如,我在一个博客上遇到了这个片段问题,实际上无法发布这些片段,因为Stack Overflow已经知道代码的问题。

然后解决了我的工作片段后,它看起来与显示解析错误

语法错误,意外的'auth''(t_constant_encapsed_string)相似,期待']'

    public $aliases = [
        'csrf'=> \CodeIgniter\Filters\CSRF::class,
        'toolbar'=> \CodeIgniter\Filters\DebugToolbar::class,
        'honeypot'=> \CodeIgniter\Filters\Honeypot::class,
        'auth' => \App\Filters\Auth::class,
];

One more reason to occurrence of these errors is unexpected whitespace like similar characters with-in code, the code lines seems to be perfect, but they contains some specific characters which are similar to break line or whitespace or tab but they not get parsed by the parser.
I face this issue when I try to put some code from webpage to the code editor by simply copy paste, I saw this error with array definition. everything was looking right in array definition. I can't sort out right error, finally I define this array in single line, then error was gone. then again I try to make that definition multiple like but manually adding break(Enter) for each array element and saved the file this time no parsing error by editor and also no error while running it.
For Example I faced issue with this snippet which was on one blog, actually can't post those snippets ,cause stack overflow already knows the problem with code.

then after solving it my working snippet is, which looks similar with one which shows parsing error

syntax error, unexpected ''auth'' (T_CONSTANT_ENCAPSED_STRING), expecting ']'

    public $aliases = [
        'csrf'=> \CodeIgniter\Filters\CSRF::class,
        'toolbar'=> \CodeIgniter\Filters\DebugToolbar::class,
        'honeypot'=> \CodeIgniter\Filters\Honeypot::class,
        'auth' => \App\Filters\Auth::class,
];
誰認得朕 2025-02-02 07:37:39

对于Newbies到VS代码,如果您看到语法错误,请检查是否保存了该文件。如果您的语法错误,保存文件,然后再次修复语法WISHOU再次保存,VS代码将继续显示错误。仅在保存文件后,错误消息才会消失。

For newbies to VS Code, if you see the syntax error, check if you have saved the file. If you have a wrong syntax, save the file, and then fix the syntax withou saving again, VS Code will keep showing you the error. The error message will disappear only after you save the file.

听风念你 2025-02-02 07:37:39

IDE是必须避免SINTAX错误的强制性的,但是诸如PHPSTAN或PHPC之类的工具也必须确保您以团队同事和代码相同的方式进行编码。

如果没有这些工具(或您的同事),只需更改几行时,您就无法在GitHub评论中找到大量的更改。

您也可以配置承诺,以便在承诺确保一切正常(紧张地说)之前与其他其他工具一起运行这些工具。

An IDE is mandatory to avoid sintax error, but tools like PHPStan or PHPCS are also mandatory to be sure you are coding in the same way your team colleagues ande your code is well indented.

Without this tools you (or your colleagues) could find tons of changes in github reviews when just a few lines were changed.

You can configure your commits as well to run these tools with others like CSSLint or ESLint before committing to be sure everything's fine (sintatically speaking).

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