Parse error syntax error, unexpected t_is_equal

parse error syntax error, unexpected t_is_equal

Parse error: syntax error, unexpected T_IS_EQUAL, expecting ',' or ')' in C:\xampp\htdocs\Adminpanel1\index.php on line 83. PHP Parse error: syntax error, unexpected T_IS_EQUAL, expecting · Full question · Question · Solution · OTHER TIPS · Read other articles. Solving syntax errors · Strings and variables and constants anycodings_php should all have different colors. · Operators +-*/. · If you see string. parse error syntax error, unexpected t_is_equal

Parse error syntax error, unexpected t_is_equal - confirm

Thread

ExpressionEngine CMS

Open, Free, Amazing

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

  • On one of my pages I have just been informed by my users is giving the following error. 

    Not sure at the moment how long that is has been there, but today I was updating a couple of plugins and as fat as I know they should not have had any impact on this page.

    Matrix
    Wygwam
    Safecraker

  • This is the first part of the teams template

  • Greetings Scott!

    The error will give you a hint as to what is going on.  The very end of the error, is:

    Do you have more than 968 lines in that file?  If so, what is on line 968?

  • Greetings Scott!

    The error will give you a hint as to what is going on.  The very end of the error, is:

    Do you have more than 968 lines in that file?  If so, what is on line 968?

    This is the code around that line

    Line 968 is the { below this line elseif (substr($file, 0, 1) != “.” && $file != ‘index.html’)

  • Apologies, I meant your template, not the expressionengine/libraries/Functions.php file.  😊

  • Doh!

    Unfortunately the template has only 429 lines.

    Bit of a weird one as I have tried a few other teams and the error gives a different line for different teams and also I have found one team the page loads fine for.

  • I think its a problem with matrix and have posted a topic on their support.

  • Hi,  Scott -

    This is a bit of an odd one.  Since you are investigating the Matrix path, I’m going to leave this open.  Will you let us know what you find out?  We can take it from there as needed.

    Thank you!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases

List of Parser Tokens

abstractClass Abstraction&=assignment operatorsarray()array(), array syntax(array)type-castingasforeach  anything below ASCII 32 except \t (0x09), \n (0x0a) and \r (0x0d) (available since PHP 7.4.0) &&logical operators logical operators(bool) or (boolean)type-castingbreakbreakcallablecallablecaseswitchcatchExceptionsclassclasses and objects__CLASS__magic constantscloneclasses and objects?> or %>escaping from HTML??comparison operators??=assignment operators (available since PHP 7.4.0) // or #, and /* */comments.=assignment operatorsconstclass constants"foo" or 'bar'string syntaxcontinuecontinue{$complex variable parsed syntax--incrementing/decrementing operatorsdeclaredeclaredefaultswitch__DIR__magic constants/=assignment operators0.12, etc.floating point numbersdodo..while/** */PHPDoc style comments${complex variable parsed syntax=>array syntax(real), (double) or (float)type-casting::see belowechoecho...function argumentselseelseelseifelseifemptyempty()" $a"constant part of string with variablesenddeclaredeclare, alternative syntaxendforfor, alternative syntaxendforeachforeach, alternative syntaxendifif, alternative syntaxendswitchswitch, alternative syntaxendwhilewhile, alternative syntax heredoc syntaxeval()eval()exit or dieexit(), die()extendsextends, classes and objects__FILE__magic constantsfinalFinal KeywordfinallyExceptionsfnarrow functions (available since PHP 7.4.0) forforforeachforeachfunctionfunctions__FUNCTION__magic constantsglobalvariable scopegotogoto__halt_compiler()__halt_compilerififimplementsObject Interfaces++incrementing/decrementing operatorsinclude()includeinclude_once()include_once text outside PHPinstanceoftype operatorsinsteadofTraitsinterfaceObject Interfaces(int) or (integer)type-castingisset()isset()==comparison operators>=comparison operators===comparison operators!= or <>comparison operators!==comparison operators<=comparison operators__LINE__magic constantslist()list()123, 012, 0x1ac, etc.integersandlogical operatorsorlogical operatorsxorlogical operators__METHOD__magic constants-=assignment operators%=assignment operators*=assignment operatorsnamespacenamespacesnewclasses and objects__NAMESPACE__namespaces\namespaces"$a[0]"numeric array index inside string(object)type-casting->classes and objects?->classes and objects<?php, <? or <%escaping from HTML<?= or <%=escaping from HTML

List of Parser Tokens

Various parts of the PHP language are represented internally by tokens. A code snippet that contains an invalid sequence of tokens may lead to errors like where token is internally represented by.

The following table lists all tokens. They are also available as PHP constants.

Note: Usage of T_* constants

T_* constants values are automatically generated based on PHP's underlying parser infrastructure. This means that the concrete value of a token may change between two PHP versions. This means that your code should never rely directly on the original T_* values taken from PHP version X.Y.Z, to provide some compatibility across multiple PHP versions, parse error syntax error.

Gzinflate data error make use of T_* constants across multiple PHP versions, undefined constants may be defined by the user (using big numbers like ) with an appropriate strategy that will work with both PHP versions and T_* values.

parsing - PHP parse/syntax errors; and how to solve them

78 votes

6 answers

Get the solution ↓↓↓

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 unexpected t_is_equal as:

PHP Parse error: syntax error, unexpected '{-code-1}' 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 . This references unexpected t_is_equal 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 unexpected t_is_equal 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 php-related, but a javascript-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.

Undefined asked




362

votes

Answer

Solution:

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 ident{-code-18}-code-11}iers. It can{-code-18}-code-8}t guess your coding intentions.

{-code-18}-code-7}Function

Most important tips

There are a few basic precautions you can always take:

How to interpret parser errors

A typical syntax error message reads:

Parse error: syntax error, unexpected t_is_equal, unexpected {-code-18}-code-4{-code-18}-code-5}-code-2{-code-18}-code-5}, expecting {-code-18}-code-8}{-code-18}-code-8} in file.php on line217

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

A moniker such as explains which symbol the parser/tokenizer couldn{-code-18}-code-8}t process finally. This isn{-code-18}-code-8}t necessarily the cause of the syntax mistake, however.

It{-code-18}-code-8}s important to look into previous code lines as well. Often syntax errors are just mishaps that happened earlier, unexpected t_is_equal. The error line number is just where the parser conclusively gave up to bwin. fatal error. the application will shutdown 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 simpl{-code-18}-code-11}y that.

  • Look at the syntax colorization!

    • Strings and variables and constants should all have d{-code-18}-code-11}ferent 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, unexpected t_is_equal, 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 {-code-18}-code-11} it{-code-18}-code-8}s not, or parentheses following an operator. Two strings/ident{-code-18}-code-11}iers directly following each other are incorrect in most contexts.

  • Whitespace is your friend. Follow any coding style. unexpected t_is_equal up long lines temporarily.

    • You can freely unexpected t_is_equal 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 statements into distinct or nested conditions.

    • Instead of lengthy unexpected t_is_equal formulas or logic chains, use temporary variables to simpl{-code-18}-code-11}y the code. (More readable = fewer errors.)

    • Add newlines between:

      1. The code you can easily ident{-code-18}-code-11}y as correct,
      2. The parts you{-code-18}-code-8}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{-code-18}-code-8}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 unexpected t_is_equal code.)

    • When you can{-code-18}-code-8}t resolve the syntax issue, try to rewrite the commented out sections from scratch.

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

    • The ternary condition operator can compact code and is useful indeed. But it doesn{-code-18}-code-8}t aid readability in all cases. Prefer plain statements while unversed.

    • PHP{-code-18}-code-8}s alternative syntax (//) is common for templates, unexpected t_is_equal, 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{-code-18}-code-8}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{-code-18}-code-8}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, parse error syntax error. (Not always though.)

  • Restore a backup of previously working code, {-code-18}-code-11} you can{-code-18}-code-8}t fix it.

    • Adopt a source code versioning system. You can always view a 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 d{-code-18}-code-11}ferent editor/viewer on your source. Some problems cannot be found just from looking at your code.

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

    • PHP just honors newlines, not carriage returns.

    • Which is occasionally an issue for MacOS users (even on OS {-code-18}-code-4{-code-18}-code-5}-code-1{-code-18}-code-5} 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), parse error syntax error. 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.

    • for the command line interpreter

    • for the one invoked through the webserver.


    Those aren{-code-18}-code-8}t necessarily the same. In particular when working with frameworks, you will them to match up.

  • Don{-code-18}-code-8}t use PHP{-code-18}-code-8}s reserved keywords as ident{-code-18}-code-11}iers 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{-code-18}-code-8}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:

    In your

    Enabling it within the broken script is too late because PHP can{-code-18}-code-8}t even interpret/run the first line. A quick workaround is crafting a wrapper script, say:

    Then invoke the failing code by accessing this wrapper script.

    It also helps to enable PHP{-code-18}-code-8}s and look into your webserver{-code-18}-code-8}s

    Undefined answered

    Link to answer



    662

    votes

    Answer

    Solution:

    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 unexpected t_is_equal syntax after every character you type. When you code and your entire line turns red, and a big unexpected t_is_equal 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)

    Undefined answered

    Link to answer



    152

    votes

    Answer

    Solution:

    Unexpected

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

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

    Reference - What does this error mean in PHP? - "Syntax error, unexpected

    Though, unexpected t_is_equal, you're always better off just upgrading your PHP installation. For shared webhosting plans, parse error syntax error, first research if e.g. 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 parse error syntax error classes, not even in PHP 7.

    • Confusing with opening curly braces or parentheses is a common oversight.

      Or even:

    • Or trying to dereference {-code-16}ants {-code-12}before PHP 5.6{-code-23} as arrays:

      At least PHP interprets that as a {-code-16}ant display error php page you meant to access an array variable {-code-12}which is the typical cause here{-code-23}, then add the canon mp150 error 40 sigil - so it becomes a.

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

    Unexpectedclosing 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:

    • Or trying to end an array where there isn't one:

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

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

    Undefined answered

    Link to answer



    703

    votes

    Answer

    Solution:

    Unexpected {-code-1{-code-16}

    An "{-code-13{-code-16}unexpected"{-code-13{-code-16} means that there's a literal name{-code-8{-code-16} which doesn't fit into the current expression/statement structure{-code-4{-code-16}

    purposefully abstract/inexact operator+{-code-2{-code-16} diagram

    1. Missing semicolon

      It most commonly indicates a missing semicolon in the previous line{-code-4{-code-16} Variable assignments following a statement are a good indicator where to look:

    2. String concatenation

      A frequent mishap are string concatenations with {-code-14{-code-16}gotten operator:

      Btw{-code-8{-code-16} you should prefer string interpolation {-code-23}basic variables in double quotes) whenever that helps readability{-code-4{-code-16} Which avoids these syntax issues{-code-4{-code-16}

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

    3. Missing expression operators

      Of course the same issue can arise in other expressions{-code-8{-code-16} {-code-14{-code-16} instance arithmetic operations:

      PHP can't guess here {-code-19} the variable should have been added{-code-8{-code-16} subtracted or compared etc{-code-4{-code-16}

    4. Lists

      Same {-code-14{-code-16} syntax {-code-11{-code-16}s{-code-8{-code-16} like in array populations{-code-8{-code-16} where the parser also indicates an expected comma {-code-14{-code-16} example:

      Or functions parameter {-code-11{-code-16}s:

      Equivalently do you see this with or statements{-code-8{-code-16} or when lacking a semicolon in a loop{-code-4{-code-16}

    5. Class declarations

      This parser error also occurs in class declarations{-code-4{-code-16} You can only assign static constants{-code-8{-code-16} not expressions{-code-4{-code-16} Thus the parser complains about variables as assigned data:

      Unmatched closing curly braces can in particular lead here{-code-4{-code-16} If a method is terminated too early {-code-23}use proper indentation!){-code-8{-code-16} then a stray variable is commonly misplaced into the class declaration body{-code-4{-code-16}

    6. Variables after ident{-code-19}iers

      You can also never have a variable follow an ident{-code-19}ier directly:

      Btw{-code-8{-code-16} this is a common example where the intention was to use variable variables perhaps{-code-4{-code-16} In this case a variable property lookup with {-code-14{-code-16} example{-code-4{-code-16}

      Take in mind that using variable variables should be the exception{-code-4{-code-16} Newcomers often try to use them too casually{-code-8{-code-16} even when arrays would be simpler and more appropriate{-code-4{-code-16}

    7. Missing parentheses after language constructs

      Hasty typing may lead to {-code-14{-code-16}gotten opening or closing parenthesis {-code-14{-code-16} and and statements:

      Solution: add the missing opening between statement and variable{-code-4{-code-16}

      The curly brace does not open the code block{-code-8{-code-16} without closing the expression with the closing parenthesis first{-code-4{-code-16}

    8. Else does not expect conditions

      Solution: Remove the conditions from or use

    9. Need brackets {-code-14{-code-16} closure

      Solution: Add brackets around{-code-4{-code-16}

    10. Invisible whitespace

      As mentioned in the reference answer on "{-code-13{-code-16}Invisible stray Unicode"{-code-13{-code-16} {-code-23}such as a non-breaking space){-code-8{-code-16} you might also see this error {-code-14{-code-16} unsuspecting code like:

      It's rather prevalent in the start of files and {-code-14{-code-16} copy-and-pasted code{-code-4{-code-16} Check with a hexeditor{-code-8{-code-16} {-code-19} your code does not visually appear to contain a syntax issue{-code-4{-code-16}

    See also

    Undefined answered

    Link to answer



    438

    votes

    Answer

    Solution:

    Unexpected T_CONSTANT_ENCAPSED_STRING
    Unexpected T_ENCAPSED_AND_WHITESPACE

    The unwieldy names and refer to quoted 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:

      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, 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:

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

      If unsure, unexpected t_is_equal, 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:

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

    3. Confusing unexpected t_is_equal 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.

      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

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

    4. Missing opening quote

      Equivalently are forgotten opening

      Here the would become a string literal after a bareword, when obviously 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:

      Note that the last line may always contain an extra comma, unexpected t_is_equal, 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:

    7. Runaway strings

      A common variation are quite simply forgotten string terminators:

      Here PHP complains about two string literals directly following each other, parse error syntax error. 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 unexpected t_is_equal with spaces:

      Solution: upgrade Unexpected t_is_equal or find a better hoster.

    See also

    Undefined answered

    Link to answer



    421

    votes

    Answer

    Solution:

    Unexpected

    is a unexpected t_is_equal of a misnomer. It does not refer to a quoted. It means a raw identifier was encountered. This can range from words to leftover 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 unexpected t_is_equal highlighting will make such mistakes super obvious. It{-code-6}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/ 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:

      This happens if 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

      It{-code-6}s not just literals which the parser may protest then. Another frequent variation is an

    3. Non-programming string quotes

      If you copy and ret 1035 install error code from a blog or website, unexpected t_is_equal, you sometimes end up with invalid code. Typographic quotes aren{-code-6}t what PHP expects:

      Typographic/smart quotes parse error syntax error Unicode symbols. PHP treats them as part of adjoining alphanumeric text. For example is interpreted as a constant identifier. But any following text literal is then seen as a {-code-3}word/ by the parser.

    4. The missing semicolon{-code-29} again

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

      PHP just can{-code-6}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 headers in PHP scripts

      This is rather uncommon. But if short_open_tags are enabled, unexpected t_is_equal, then you can{-code-6}t begin your PHP scripts with an XML declaration:

    Undefined answered

    Link to answer



    People are also looking for solutions to the problem: call to a member function update() on null
    Source

    Share


    Didn't find the answer?

    Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

    Ask a Question


    Similar questions

    Find the answer in similar questions on our website.

    223javascript - META Tags "Refresh" Alternative - "<?php header("Location:. ?>": Issues with php echo in php

    391mysql - Paging with php without using limit syntax

    355php - Optimalize sql syntax

    474php - How To Disable The WordPress Theme Editor

    438php - Is there a solid way to use the Zurb Foundation CSS framework with CakePHP?

    119Php Login errors

    844cakephp - PHP using exit()

    24php cd-rom error 0x73 Relative path doesnt work after include?

    475how to retrieve blob file to image in php?

    162HTML form within PHP tags

    Write quick answer

    Do you know the answer to this question? Write a quick response to it, parse error syntax error. With your help, we will make our community stronger.




    About the technologies asked in this question

    PHP

    PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites. The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
    https://www.php.net/


    Laravel

    Laravel is a free open source PHP framework that came out in 2011. Since then, it has been able to become the framework of choice for web developers. One of the main reasons for this is that Laravel makes it easier, faster, and safer to develop complex web applications than any other framework.
    https://laravel.com/


    JavaScript

    JavaScript is a multi-paradigm language that supports event-driven, functional, and mandatory (including object-oriented and prototype-based) programming types. Originally JavaScript was only used on the client side. JavaScript is now still used as a server-side programming language. To summarize, we can say that JavaScript is the language of the Internet.
    https://www.javascript.com/


    MySQL

    DBMS is a database management system, unexpected t_is_equal. It is designed to change, unexpected t_is_equal, search, add and delete information in the database. There are many DBMSs designed for similar purposes with different features. One of the most popular is MySQL. It is a software tool designed to work with relational SQL databases. It is easy to learn even for site owners who are not professional programmers or administrators. MySQL DBMS also allows you to export and import data, which is convenient when moving large amounts of information.
    https://www.mysql.com/


    HTML

    HTML (English "hyper text markup unexpected t_is_equal - hypertext markup language) is a special markup language that is used to create sites on the Internet. Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser parse error syntax error into a user-friendly form. By the way, the code of any page is available to everyone.
    https://www.w3.org/html/



    Welcome to programmierfrage.com

    Welcome to programmierfrage.com

    programmierfrage.com is a question and answer site for professional web developers, parse error syntax error, programming enthusiasts and website builders. Site created and operated by the community. Together with you, we create a free library of detailed answers to any question on programming, web development, website creation and website administration.

    Get answers to specific questions

    Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.

    Help Others Solve Their Issues

    Our parse error syntax error is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.

    Parse error syntax error, unexpected t_is_equal - And have

    parsing - PHP parse/syntax errors; and how to solve them

    78 votes

    6 answers

    Get the solution ↓↓↓

    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 '{-code-1}' 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 . 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 php-related, but a javascript-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.

    Undefined asked




    362

    votes

    Answer

    Solution:

    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 ident{-code-18}-code-11}iers. It can{-code-18}-code-8}t guess your coding intentions.

    {-code-18}-code-7}Function

    Most important tips

    There are a few basic precautions you can always take:

    How to interpret parser errors

    A typical syntax error message reads:

    Parse error: syntax error, unexpected {-code-18}-code-4{-code-18}-code-5}-code-2{-code-18}-code-5}, expecting {-code-18}-code-8}{-code-18}-code-8} in file.php on line217

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

    A moniker such as explains which symbol the parser/tokenizer couldn{-code-18}-code-8}t process finally. This isn{-code-18}-code-8}t necessarily the cause of the syntax mistake, however.

    It{-code-18}-code-8}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 simpl{-code-18}-code-11}y that.

    • Look at the syntax colorization!

      • Strings and variables and constants should all have d{-code-18}-code-11}ferent 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 {-code-18}-code-11} it{-code-18}-code-8}s not,, or parentheses following an operator. Two strings/ident{-code-18}-code-11}iers 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 statements into distinct or nested conditions.

      • Instead of lengthy math formulas or logic chains, use temporary variables to simpl{-code-18}-code-11}y the code. (More readable = fewer errors.)

      • Add newlines between:

        1. The code you can easily ident{-code-18}-code-11}y as correct,
        2. The parts you{-code-18}-code-8}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{-code-18}-code-8}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{-code-18}-code-8}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{-code-18}-code-8}t aid readability in all cases. Prefer plain statements while unversed.

      • PHP{-code-18}-code-8}s alternative syntax (//) 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{-code-18}-code-8}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{-code-18}-code-8}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, {-code-18}-code-11} you can{-code-18}-code-8}t fix it.

      • Adopt a source code versioning system. You can always view a 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 d{-code-18}-code-11}ferent editor/viewer on your source. Some problems cannot be found just from looking at your code.

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

      • PHP just honors newlines, not carriage returns.

      • Which is occasionally an issue for MacOS users (even on OS {-code-18}-code-4{-code-18}-code-5}-code-1{-code-18}-code-5} 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.

      • for the command line interpreter

      • for the one invoked through the webserver.


      Those aren{-code-18}-code-8}t necessarily the same. In particular when working with frameworks, you will them to match up.

    • Don{-code-18}-code-8}t use PHP{-code-18}-code-8}s reserved keywords as ident{-code-18}-code-11}iers 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{-code-18}-code-8}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:

      In your

      Enabling it within the broken script is too late because PHP can{-code-18}-code-8}t even interpret/run the first line. A quick workaround is crafting a wrapper script, say:

      Then invoke the failing code by accessing this wrapper script.

      It also helps to enable PHP{-code-18}-code-8}s and look into your webserver{-code-18}-code-8}s

      Undefined answered

      Link to answer



      662

      votes

      Answer

      Solution:

      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)

      Undefined answered

      Link to answer



      152

      votes

      Answer

      Solution:

      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 function result dereferencing is likewise not available for older PHP versions:

      Reference - What does this error mean in PHP? - "Syntax error, unexpected

      Though, you're always better off just upgrading your PHP installation. For shared webhosting plans, first research if e.g. 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.

      • Confusing with opening curly braces or parentheses is a common oversight.

        Or even:

      • Or trying to dereference {-code-16}ants {-code-12}before PHP 5.6{-code-23} as arrays:

        At least PHP interprets that as a {-code-16}ant name.

        If you meant to access an array variable {-code-12}which is the typical cause here{-code-23}, then add the leading sigil - so it becomes a.

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

      Unexpectedclosing 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:

      • Or trying to end an array where there isn't one:

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

        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.

      Undefined answered

      Link to answer



      703

      votes

      Answer

      Solution:

      Unexpected {-code-1{-code-16}

      An "{-code-13{-code-16}unexpected"{-code-13{-code-16} means that there's a literal name{-code-8{-code-16} which doesn't fit into the current expression/statement structure{-code-4{-code-16}

      purposefully abstract/inexact operator+{-code-2{-code-16} diagram

      1. Missing semicolon

        It most commonly indicates a missing semicolon in the previous line{-code-4{-code-16} Variable assignments following a statement are a good indicator where to look:

      2. String concatenation

        A frequent mishap are string concatenations with {-code-14{-code-16}gotten operator:

        Btw{-code-8{-code-16} you should prefer string interpolation {-code-23}basic variables in double quotes) whenever that helps readability{-code-4{-code-16} Which avoids these syntax issues{-code-4{-code-16}

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

      3. Missing expression operators

        Of course the same issue can arise in other expressions{-code-8{-code-16} {-code-14{-code-16} instance arithmetic operations:

        PHP can't guess here {-code-19} the variable should have been added{-code-8{-code-16} subtracted or compared etc{-code-4{-code-16}

      4. Lists

        Same {-code-14{-code-16} syntax {-code-11{-code-16}s{-code-8{-code-16} like in array populations{-code-8{-code-16} where the parser also indicates an expected comma {-code-14{-code-16} example:

        Or functions parameter {-code-11{-code-16}s:

        Equivalently do you see this with or statements{-code-8{-code-16} or when lacking a semicolon in a loop{-code-4{-code-16}

      5. Class declarations

        This parser error also occurs in class declarations{-code-4{-code-16} You can only assign static constants{-code-8{-code-16} not expressions{-code-4{-code-16} Thus the parser complains about variables as assigned data:

        Unmatched closing curly braces can in particular lead here{-code-4{-code-16} If a method is terminated too early {-code-23}use proper indentation!){-code-8{-code-16} then a stray variable is commonly misplaced into the class declaration body{-code-4{-code-16}

      6. Variables after ident{-code-19}iers

        You can also never have a variable follow an ident{-code-19}ier directly:

        Btw{-code-8{-code-16} this is a common example where the intention was to use variable variables perhaps{-code-4{-code-16} In this case a variable property lookup with {-code-14{-code-16} example{-code-4{-code-16}

        Take in mind that using variable variables should be the exception{-code-4{-code-16} Newcomers often try to use them too casually{-code-8{-code-16} even when arrays would be simpler and more appropriate{-code-4{-code-16}

      7. Missing parentheses after language constructs

        Hasty typing may lead to {-code-14{-code-16}gotten opening or closing parenthesis {-code-14{-code-16} and and statements:

        Solution: add the missing opening between statement and variable{-code-4{-code-16}

        The curly brace does not open the code block{-code-8{-code-16} without closing the expression with the closing parenthesis first{-code-4{-code-16}

      8. Else does not expect conditions

        Solution: Remove the conditions from or use

      9. Need brackets {-code-14{-code-16} closure

        Solution: Add brackets around{-code-4{-code-16}

      10. Invisible whitespace

        As mentioned in the reference answer on "{-code-13{-code-16}Invisible stray Unicode"{-code-13{-code-16} {-code-23}such as a non-breaking space){-code-8{-code-16} you might also see this error {-code-14{-code-16} unsuspecting code like:

        It's rather prevalent in the start of files and {-code-14{-code-16} copy-and-pasted code{-code-4{-code-16} Check with a hexeditor{-code-8{-code-16} {-code-19} your code does not visually appear to contain a syntax issue{-code-4{-code-16}

      See also

      Undefined answered

      Link to answer



      438

      votes

      Answer

      Solution:

      Unexpected T_CONSTANT_ENCAPSED_STRING
      Unexpected T_ENCAPSED_AND_WHITESPACE

      The unwieldy names and refer to quoted 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:

        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, 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:

        Nested arrays or deeper object references however require the complex curly string expression 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:

        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.

        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

        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

        Here the would become a string literal after a bareword, when obviously 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:

        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:

      7. Runaway strings

        A common variation are quite simply forgotten string terminators:

        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:

        Solution: upgrade PHP or find a better hoster.

      See also

      Undefined answered

      Link to answer



      421

      votes

      Answer

      Solution:

      Unexpected

      is a bit of a misnomer. It does not refer to a quoted. It means a raw identifier was encountered. This can range from words to leftover 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:

        Syntax highlighting will make such mistakes super obvious. It{-code-6}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/ 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:

        This happens if 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

        It{-code-6}s not just literals which the parser may protest then. Another frequent variation is an

      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{-code-6}t what PHP expects:

        Typographic/smart quotes are Unicode symbols. PHP treats them as part of adjoining alphanumeric text. For example is interpreted as a constant identifier. But any following text literal is then seen as a {-code-3}word/ by the parser.

      4. The missing semicolon{-code-29} again

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

        PHP just can{-code-6}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 headers in PHP scripts

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

      Undefined answered

      Link to answer



      People are also looking for solutions to the problem: call to a member function update() on null
      Source

      Share


      Didn't find the answer?

      Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

      Ask a Question


      Similar questions

      Find the answer in similar questions on our website.

      223javascript - META Tags "Refresh" Alternative - "<?php header("Location:.. ?>": Issues with php echo in php

      391mysql - Paging with php without using limit syntax

      355php - Optimalize sql syntax

      474php - How To Disable The WordPress Theme Editor

      438php - Is there a solid way to use the Zurb Foundation CSS framework with CakePHP?

      119Php Login errors

      844cakephp - PHP using exit()

      24php - Relative path doesnt work after include?

      475how to retrieve blob file to image in php?

      162HTML form within PHP tags

      Write quick answer

      Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.




      About the technologies asked in this question

      PHP

      PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites. The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
      https://www.php.net/


      Laravel

      Laravel is a free open source PHP framework that came out in 2011. Since then, it has been able to become the framework of choice for web developers. One of the main reasons for this is that Laravel makes it easier, faster, and safer to develop complex web applications than any other framework.
      https://laravel.com/


      JavaScript

      JavaScript is a multi-paradigm language that supports event-driven, functional, and mandatory (including object-oriented and prototype-based) programming types. Originally JavaScript was only used on the client side. JavaScript is now still used as a server-side programming language. To summarize, we can say that JavaScript is the language of the Internet.
      https://www.javascript.com/


      MySQL

      DBMS is a database management system. It is designed to change, search, add and delete information in the database. There are many DBMSs designed for similar purposes with different features. One of the most popular is MySQL. It is a software tool designed to work with relational SQL databases. It is easy to learn even for site owners who are not professional programmers or administrators. MySQL DBMS also allows you to export and import data, which is convenient when moving large amounts of information.
      https://www.mysql.com/


      HTML

      HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet. Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
      https://www.w3.org/html/



      Welcome to programmierfrage.com

      Welcome to programmierfrage.com

      programmierfrage.com is a question and answer site for professional web developers, programming enthusiasts and website builders. Site created and operated by the community. Together with you, we create a free library of detailed answers to any question on programming, web development, website creation and website administration.

      Get answers to specific questions

      Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.

      Help Others Solve Their Issues

      Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.

      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 line217

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

      A moniker such as 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 statements into distinct or nested 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 statements while unversed.

        • PHP's alternative syntax (//) 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 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 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 newlines, not 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.

        • for the command line interpreter

        • 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:

        In your generally, or via for mod_php, or even 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 :

        Then invoke the failing code by accessing this wrapper script.

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

        List of Parser Tokens

        Various parts of the PHP language are represented internally by tokens. A code snippet that contains an invalid sequence of tokens may lead to errors like where token is internally represented by .

        The following table lists all tokens. They are also available as PHP constants.

        Note: Usage of T_* constants

        T_* constants values are automatically generated based on PHP's underlying parser infrastructure. This means that the concrete value of a token may change between two PHP versions. This means that your code should never rely directly on the original T_* values taken from PHP version X.Y.Z, to provide some compatibility across multiple PHP versions.

        To make use of T_* constants across multiple PHP versions, undefined constants may be defined by the user (using big numbers like ) with an appropriate strategy that will work with both PHP versions and T_* values.

        TokenSyntaxReference
        abstractClass Abstraction
        &Type declarations (available as of PHP 8.1.0)
        &Type declarations (available as of PHP 8.1.0)
        &=assignment operators
        array()array(), array syntax
        (array)type-casting
        asforeach
        #[attributes (available as of PHP 8.0.0)
          windows socket error share anything below ASCII 32 except \t (0x09), \n (0x0a) and \r (0x0d) (available as of PHP 7.4.0)
        &&logical operators

        List of Parser Tokens

        abstractClass Abstraction
        &=assignment operators
        array()array(), array syntax
        (array)type-casting
        asforeach
          anything below ASCII 32 except \t (0x09), \n (0x0a) and \r (0x0d) (available since PHP 7.4.0)
        &&logical operators
        =assignment operators
        ::::. Also defined as .
        +=assignment operators
        **arithmetic operators
        **=assignment operators
        print()print
        privateclasses and objects
        protectedclasses and objects
        publicclasses and objects
        require()require
        require_once()require_once
        returnreturning values
        <<bitwise operators
        <<=assignment operators
        <=>comparison operators
        >>bitwise operators
        >>=assignment operators
        <<<heredoc unexpected t_is_equal syntax
        staticvariable scope
        parent, self, etc. identifiers, e.g. keywords like and function names, class names and more are matched. See also.
        (string)type-casting
        "${acomplex variable parsed syntax
        switchswitch
        throwExceptions
        traitTraits
        __TRAIT____TRAIT__
        tryExceptions
        unset()unset()
        (unset)type-casting
        usenamespaces
        varclasses and objects
        $foovariables
        whilewhile, do.while
        \t \r\n 
        ^=assignment operators
        yieldgenerators
        yield fromgenerators
        TokenSyntaxReference
        abstractClass Abstraction
        &Type declarations (available as of PHP 8.1.0)
        &Type declarations (available as of PHP 8.1.0)
        &=assignment operators
        array()array(), array syntax
        (array)type-casting
        asforeach
        #[attributes (available as of PHP 8.0.0)
          anything below ASCII 32 except \t (0x09), \n (0x0a) and \r (0x0d) (available as of PHP 7.4.0)
        &&logical operators

        List of Parser Tokens

        abstractClass Abstraction
        &=assignment operators
        array()array(), array syntax
        (array)type-casting
        asforeach
          anything below ASCII 32 except \t (0x09), \n (0x0a) and \r (0x0d) (available since PHP 7.4.0)
        &&logical operators
        logical operators
        (bool) or (boolean)type-casting
        breakbreak
        callablecallable
        caseswitch
        catchExceptions
        classclasses and objects
        __CLASS__magic constants
        cloneclasses and objects
        ?> or %>escaping from HTML
        ??comparison operators
        ??=assignment operators (available as of PHP 7.4.0)
        // or #, and /* */comments
        .=assignment operators
        constclass constants
        "foo" or 'bar'string syntax
        continuecontinue
        {$complex variable parsed syntax
        --incrementing/decrementing operators
        declaredeclare
        defaultswitch
        __DIR__magic constants
        /=assignment operators
        0.12, etc.floating point numbers
        dodo..while
        /** */PHPDoc style comments
        ${complex variable parsed syntax
        =>array syntax
        (real), (double) or (float)type-casting
        ::see below
        echoecho
        ...function arguments
        elseelse
        elseifelseif
        emptyempty()
        " $a"constant part of string with variables
        enddeclaredeclare, alternative syntax
        endforfor, alternative syntax
        endforeachforeach, alternative syntax
        endifif, alternative syntax
        endswitchswitch, alternative syntax
        endwhilewhile, alternative syntax
        enumEnumerations (available as of PHP 8.1.0)
         heredoc syntax
        eval()eval()
        exit or dieexit(), die()
        extendsextends, classes and objects
        __FILE__magic constants
        finalFinal Keyword
        finallyExceptions
        fnarrow functions (available as of PHP 7.4.0)
        forfor
        foreachforeach
        functionfunctions
        __FUNCTION__magic constants
        globalvariable scope
        gotogoto
        __halt_compiler()__halt_compiler
        ifif
        implementsObject Interfaces
        ++incrementing/decrementing operators
        include()include
        include_once()include_once
         text outside PHP
        instanceoftype operators
        insteadofTraits
        interfaceObject Interfaces
        (int) or (integer)type-casting
        isset()isset()
        ==comparison operators
        >=comparison operators
        ===comparison operators
        != or <>comparison operators
        !==comparison operators
        <=comparison operators
        __LINE__magic constants
        list()list()
        123, 012, 0x1ac, etc.integers
        andlogical operators
        orlogical operators
        xorlogical operators
        matchmatch (available as of PHP 8.0.0)
        __METHOD__magic constants
        -=assignment operators
        %=assignment operators
        *=assignment operators
        namespacenamespaces
        \App\Namespacenamespaces (available as of PHP 8.0.0)
        App\Namespacenamespaces (available as of PHP 8.0.0)
        namespace\Namespacenamespaces (available as of PHP 8.0.0)
        newclasses and objects
        __NAMESPACE__namespaces
        \namespaces
        "$a[0]"numeric array index inside string
        (object)type-casting
        ->classes and objects
        ?->classes and objects
        <?php, <? or <%escaping from HTML
        <?= or <%=escaping from HTML
        logical operators
        (bool) or (boolean)type-casting
        breakbreak
        callablecallable
        caseswitch
        catchExceptions
        classclasses and objects
        __CLASS__magic constants
        cloneclasses and objects
        ?> or %>escaping from HTML
        ??comparison operators
        ??=assignment operators (available since PHP 7.4.0)
        // or #, and /* */comments
        .=assignment operators
        constclass constants
        "foo" or 'bar'string syntax
        continuecontinue
        {$complex variable parsed syntax
        --incrementing/decrementing operators
        declaredeclare
        defaultswitch
        __DIR__magic constants
        /=assignment operators
        0.12, etc.floating point numbers
        dodo..while
        /** */PHPDoc style comments
        ${complex variable parsed syntax
        =>array syntax
        (real), (double) or (float)type-casting
        ::see below
        echoecho
        ...function arguments
        elseelse
        elseifelseif
        emptyempty()
        " $a"constant part of string with variables
        enddeclaredeclare, alternative syntax
        endforfor, alternative syntax
        endforeachforeach, alternative syntax
        endifif, alternative syntax
        endswitchswitch, alternative syntax
        endwhilewhile, alternative syntax
         heredoc syntax
        eval()eval()
        exit or dieexit(), die()
        extendsextends, classes and objects
        __FILE__magic constants
        finalFinal Keyword
        finallyExceptions
        fnarrow functions (available since PHP 7.4.0)
        forfor
        foreachforeach
        functionfunctions
        __FUNCTION__magic constants
        globalvariable scope
        gotogoto
        __halt_compiler()__halt_compiler
        ifif
        implementsObject Interfaces
        ++incrementing/decrementing operators
        include()include
        include_once()include_once
         text outside PHP
        instanceoftype operators
        insteadofTraits
        interfaceObject Interfaces
        (int) or (integer)type-casting
        isset()isset()
        ==comparison operators
        >=comparison operators
        ===comparison operators
        != or <>comparison operators
        !==comparison operators
        <=comparison operators
        __LINE__magic constants
        list()list()
        123, 012, 0x1ac, etc.integers
        andlogical operators
        orlogical operators
        xorlogical operators
        __METHOD__magic constants
        -=assignment operators
        %=assignment operators
        *=assignment operators
        namespacenamespaces
        newclasses and objects
        __NAMESPACE__namespaces
        \namespaces
        "$a[0]"numeric array index inside string
        (object)type-casting
        ->classes and objects
        ?->classes and objects
        <?php, <? or <%escaping from HTML
        <?= or <%=escaping from HTML
        =assignment operators
        ::::. Also defined as .
        +=assignment operators
        **arithmetic operators
        **=assignment operators
        print()print
        privateclasses and objects
        protectedclasses and objects
        publicclasses and objects
        readonlyclasses and objects (available as of PHP 8.1.0)
        require()require
        require_once()require_once
        returnreturning values
        <<bitwise operators
        <<=assignment operators
        <=>comparison operators
        >>bitwise operators
        >>=assignment operators
        <<<heredoc syntax
        staticvariable scope
        parent, self, etc. identifiers, e.g. keywords like and , function names, class names and more are matched. See also .
        (string)type-casting
        "${acomplex variable parsed syntax
        switchswitch
        throwExceptions
        traitTraits
        __TRAIT____TRAIT__
        tryExceptions
        unset()unset()
        (unset)type-casting
        usenamespaces
        varclasses and objects
        $foovariables
        whilewhile, do..while
        \t \r\n 
        ^=assignment operators
        yieldgenerators
        yield fromgenerators

        See also token_name().

        add a note

        User Contributed Notes 2 notes

        nathan at unfinitydesign dot com

        13 years ago

        fgm at osinet dot fr

        13 years ago

        To Top

        0 Comments

        Leave a Comment