-2

In multiple error messages, there is mention of a T-CONSTANT-ENCAPSED-STRING.

There is usually a solution that it is a simple syntax error, but it not actually told what the meaning of T_CONSTANT-ENCAPSED-STRING is.

But I'd like to learn more about it.

Is it ...

  • ... a data type?
  • ... a special error message syntax?
hakre
  • 193,403
  • 52
  • 435
  • 836
  • 1
    possible duplicate of [Reference - What does this error mean in PHP?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – Rizier123 Dec 23 '14 at 20:10
  • You don't show any effort to research it yourself! – Rizier123 Dec 23 '14 at 20:11
  • 1
    Not a duplicate. If you look at all the questions concerning a t-constant-encapsed-string, all of them are looking for a solution to an error: however, none of them explain what it is. Do your research. –  Dec 23 '14 at 20:12
  • 3
    The PHP web site includes a complete list of parser tokens [here](http://php.net/manual/en/tokens.php) –  Dec 23 '14 at 20:12
  • 1. Means you have to escape double quotes in single quotes or the other way around: `'"'` -> `'\"'` 2. You would have found that in 1 min if you search that in google! (Also see: http://stackoverflow.com/q/19041003/3933332) – Rizier123 Dec 23 '14 at 20:16
  • 1
    @Rizier123 If you had done any more research other than clicking the first result, you would know that there are cases where that's not what happens. –  Dec 23 '14 at 20:19
  • maybe you need to include some code...there should be some kind of indication as to what line the compile time error occurs? possibly provide a link where others experience the same issue but it is unsolved? – Logan Murphy Dec 23 '14 at 20:23
  • If this is related to code you're having trouble with, post it. Otherwise the duplicate will stand. – Funk Forty Niner Dec 23 '14 at 20:23
  • 1
    It seems I was unclear. **This is not an error report**. I am not asking for anyone to debug my code. I am simply wondering what a T-Constant-Encapsed-String is. I thought my grammar implicitly stated this - but I guess I was wrong. –  Dec 23 '14 at 20:24
  • All we are suggesting is that if there are multiple causes to this syntax error it would be best to post the one most confusing to you that way we can properly explain it – Logan Murphy Dec 23 '14 at 20:29
  • Did you mean `T_CONSTANT_ENCAPSED_STRING`? Can you provide some of the error messages you ask about (just exemplary)? – hakre Dec 23 '14 at 20:40
  • 1
    Thanks guys, but I found a more useful answer at http://w3schools.invisionzone.com/index.php?showtopic=30864. The T simply represents that it is an error, Constant represents that the Encapsed String is a constant, encapsed string represents a string surrounded by quotes. @Rizier123 your escaping comment was a nice try, but it is completely unrelated. –  Dec 23 '14 at 20:47

2 Answers2

2

T_CONSTANT_ENCAPSED_STRING is one of a number of tokens generated by the PHP parser as it creates the PHP byte code. A complete list of them is here.

On its own it merely signifies that the parser has encountered a quoted string as a literal, for example

$a = "something";

where "something" is the item referred to by T_CONSTANT_ENCAPSED_STRING. (It also applies to 'something' the variant with single-quotes, see String Syntax).

In the context of an error message it indicates that a quoted string has been found where it wasn't expected. This is usually, though not always, due to unmatched quotes somewhere in the program.

hakre
  • 193,403
  • 52
  • 435
  • 836
1

First of all T_CONSTANT_ENCAPSED_STRING is the name of a constant in PHP. It represents a number (see this in different PHP versions).

T_ is the prefix for Token (it does not represent an error but a token). A token is when a PHP file is parsed, the text - letter for letter - is arranged into tokens. This helps the PHP parser to better decipher the syntax from the text.

When the parser then turned the source-text into tokens and it stumbles over a token the parser didn't expect, an error message is created giving the name of the token that was not expected. For example the token in your question: T_CONSTANT_ENCAPSED_STRING.

This on it's own is a bit cryptic and the error message itself doesn't explain the token at all, however the PHP manual has a list of all tokens: http://php.net/tokens.

So what you got here is the token with the number that is also represented by the constant named T_CONSTANT_ENCAPSED_STRING. Apart from the T_ prefix the rest of the constant name does not follow much of a sheme which is why - if you want to find out more about a specific T_... constant - you need to consult the token list at http://php.net/tokens.

hakre
  • 193,403
  • 52
  • 435
  • 836