4

I have this line in PHP:

$bom != b"\xEF\xBB\xBF" 

When I run it, I get the error:

Parse error: syntax error, unexpected T_NS_SEPARATOR in
C:\xampp\htdocs\MediaAlbumWeb\Utils\Utils.php on line 218

What is the T_NS_SEPARATOR in php and why is it unexpected?

Community
  • 1
  • 1
  • 1
    That line has no parse errors. Paste your entire code if possible or atleast few lines before line 218. – codaddict Jun 07 '11 at 09:20
  • please show some more code relevant to this. – Gaurav Jun 07 '11 at 09:20
  • 1
    just a wild guess: try removing the `b` before the string. the error message hints at namespaces though – knittl Jun 07 '11 at 09:21
  • @codaddict Actually, there is a parse error: it's the b, which PHP sees as a constant, followed by a string. The only that'd ever work if there was a concatenation in between ('.'). Nonetheless, I just think the "b" should be left out altogether. – Berry Langerak Jun 07 '11 at 09:24
  • @Berry: http://www.ideone.com/jf7Ij – codaddict Jun 07 '11 at 09:26
  • 1
    @codaddict, what the... I've never seen this before, but I just tested it on my machine and it actually seems to work. Do you have a link to the documentation? – Berry Langerak Jun 07 '11 at 09:28
  • You have likely something like `\"` more up so that `"` is closing the string and \ is the unexpected `T_NS_SEPARATOR`. - x-ref: http://stackoverflow.com/questions/14751994/parse-error-issue-which-i-cant-solve ; del-ref http://stackoverflow.com/questions/6454797/t-ns-separator-error-in-php – hakre Mar 04 '13 at 03:50
  • The `b''` syntax is available since PHP 5.2.1... – Martin Tournoij Aug 14 '14 at 12:44

2 Answers2

7

You likely have an unclosed single or double quote above that line in your code.

What is the b that's outside of the quotes?

If it's a comparison, it could be something like:

if($bom != "b\xEF\xBB\xBF")
{
 //code
}

Simple code to reproduce this error in PHP:

<?php
$arg = "'T';                      //this unclosed double quote is perfectly fine.

$vehicle = ( $arg == 'B' ? 'bus' : 'not a bus');

print $vehicle . "\n";            //error is thrown on this line.  

?>

Run this, it prints an error:

PHP Parse error:  syntax error, unexpected T_NS_SEPARATOR in 
/var/www/sandbox/eric/code/php/run08/a.php on line 6
Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Brendan Bullen
  • 11,607
  • 1
  • 31
  • 40
0

You do a lot of Python, by any chance? b"string" is not a valid way to write your string in PHP, though it is in Python. If you just want the bytes, then you can write the string out as:

echo "\xEF\xBB\xBF";

That works. If you want to check for inequality:

if( $bom != "\xEF\xBB\xBF" ) {
}

What are you checking for anyway? For a Byte Order Mark? And if so: why, exactly?

Berry Langerak
  • 18,561
  • 4
  • 45
  • 58