Parse error: syntax error, unexpected $end in /sites/all/modules/search_api/search_api.admin.inc on line 1924

I tried using php version 5.3.2 and 5.2.5. I'm not sure how this is happening, since that line is actually the end of the file. Strangely enough on my mac the module works with only minor indexing problems. I only installed the module and activated the database search engine.

I even tried this with a clean install I did have some other modules installed though.

ctools
date
email_registration
entity
field_group
libraries
pathauto
profile2
search_api
superfish
token
views

If you need more info just let me know.

CommentFileSizeAuthor
#6 search_api.syntax_error.patch625 bytesdrunken monkey

Comments

drunken monkey’s picture

This is really weird. Syntax error practically can't be the result of special configuration or such things, they are actual errors in the file itself. The one you posted refers to a quoted string or a control structure not correctly closed.
However, if this would be the case, no one else could use that version, including me. Since it worked for everyone else, this has to be some weird bug on your end. Maybe downloading didn't work correctly for some reason? Could you maybe control the checksum of the downloaded release archive, and/or re-download the module?
You could also try to only parse the one PHP file, on the command line (with "php search_api.admin.inc") to see if this also produces the error. Otherwise, it would probably be a malfunction of yyour web server, though I don't know what could cause such a thing.

In any case, I'm very sure that the module itself isn't guilty here.

emagus’s picture

i am getting the same error.
actually with any version i tried, i.e. beta 7 & 8 as well as the latest dev

drunken monkey’s picture

OK, that's really bad. Then there probably really is something the problem with the file itself …
Could you execute the file on the command line, as suggested above?
If this triggers the error, you could then incrementally remove functions from the end of the file to see which is the one containing the error. (When doing this with the web server, you should do it on the Search API overview page, as that reduces the chance that you'll get a "function not found" error before the other one disappears.)

emagus’s picture

the error disappears when i remove this function: search_api_admin_index_fields_submit
when executing the file outside of its environment.

emagus’s picture

i found this weird line in that function:

line 1759: $name_prefix .= $wrapper_info['label'] . ' » ';

Could that be related to the problem?

drunken monkey’s picture

Title: Parse error: syntax error in newest beta 8 » Possible syntax error in search_api.admin.inc
Version: 7.x-1.0-beta8 » 7.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new625 bytes

Thanks for finding this out! Now I spotted the problem – it's the two characters "%>" in the comment, which will end the PHP block for some (deprecated) php.ini configurations (i.e., "asp_tags = On").
The attached patch should fix this.

The "»" merely means you are viewing the file with a wrong file encoding (right is UTF-8).

emagus’s picture

Status: Needs review » Reviewed & tested by the community

works! Thank you :-)

emagus’s picture

Title: Possible syntax error in search_api.admin.inc » Possible syntax error in search_api.admin.inc and search_api_db/service.inc
Status: Reviewed & tested by the community » Needs work

hm getting the same error, when I try to set db server now:

Parse error: syntax error, unexpected $end in .../sites/all/modules/search_api/contrib/search_api_db/service.inc on line 676

turned asp_tags off btw

drunken monkey’s picture

Title: Possible syntax error in search_api.admin.inc and search_api_db/service.inc » Possible syntax error in search_api.admin.inc
Status: Needs work » Fixed

Great – committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

danielnolde’s picture

For any passers-by who struggle with similar "unexpected $end" PHP errors: This is a very very ver strange error which happens sometimes in conjunction with vm images, with php files that live in a mounted host system directory but are programmatically created/downloaded inside of a vm image (like "drush dl"-downloaded or "drush fu"-updated files). Can't explain what's actually going on there, but the workaround is easy: Delete and Re-Enter the file's last line (jump to the end of the erroneous file, press backspace, then press return).
If anybody knows more about this, contact me!!!