Quantcast
Channel: PHP parse/syntax errors; and how to solve them - Stack Overflow
Browsing all 22 articles
Browse latest View live

Answer by David Spector for PHP parse/syntax errors; and how to solve them?

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.

View Article



Answer by mplungjan for PHP parse/syntax errors; and how to solve them?

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...

View Article

Answer by John Conde for PHP parse/syntax errors; and how to solve them?

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...

View Article

Answer by John Conde for PHP parse/syntax errors; and how to solve them?

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...

View Article

Answer by John Conde for PHP parse/syntax errors; and how to solve them?

Unexpected '?' 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; //...

View Article


Image may be NSFW.
Clik here to view.

Answer by John Conde for PHP parse/syntax errors; and how to solve them?

Unexpected T_LNUMBER The token T_LNUMBER refers to a "long" / number. Invalid variable names In PHP, and most other programming languages, variables cannot start with a number. The first character must...

View Article

Image may be NSFW.
Clik here to view.

Answer by mario for PHP parse/syntax errors; and how to solve them?

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...

View Article

Answer by mario for PHP parse/syntax errors; and how to solve them?

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...

View Article


Answer by mario for PHP parse/syntax errors; and how to solve them?

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()....

View Article


Image may be NSFW.
Clik here to view.

Answer by mario for PHP parse/syntax errors; and how to solve them?

Unexpected $end When PHP talks about an "unexpected $end", it means that your code ended prematurely. (The message is a bit misleading when taken literally. It's not about a variable named "$end", as...

View Article

Answer by Sliq for PHP parse/syntax errors; and how to solve them?

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....

View Article

Answer by mario for PHP parse/syntax errors; and how to solve them?

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...

View Article

Answer by mario for PHP parse/syntax errors; and how to solve them?

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...

View Article


Answer by mario for PHP parse/syntax errors; and how to solve them?

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...

View Article

Answer by mario for PHP parse/syntax errors; and how to solve them?

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...

View Article


Image may be NSFW.
Clik here to view.

Answer by mario for PHP parse/syntax errors; and how to solve them?

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. Missing semicolon It most commonly...

View Article

Image may be NSFW.
Clik here to view.

Answer by mario for PHP parse/syntax errors; and how to solve them?

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....

View Article


PHP parse/syntax errors; and how to solve them?

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...

View Article

Answer by John Conde for PHP parse/syntax errors; and how to solve them

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...

View Article

Answer by ofri cofri for PHP parse/syntax errors; and how to solve them

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...

View Article
Browsing all 22 articles
Browse latest View live


Latest Images