Jump to content
wclarke

Syntax error thrown when no syntax error

Recommended Posts

The issue is there seems to be NO syntax error.

1. There is no relevant code before or after this line. 2. Yes, one would think a ! should be there as did I (I didn't write the code), however, even with the ! it still gives the same error.

if (function_exists('gzcompress')) die(FUNCTION_NOT_FOUND); is giving me a

syntax error, unexpected 'if', expecting 'function' or 'const'

I am updating this code from PHP5.3 to PHP7.4 and I can't figure out what the syntax problem is since PHP allows this. I am using Eclipse PHP to do the conversion.

Share this post


Link to post
Share on other sites

How about posting the rest of the code instead of just that one line?

Share this post


Link to post
Share on other sites

You are getting that error because the syntax of something previous is wrong.

Share this post


Link to post
Share on other sites

Is FUNCTION_NOT_FOUND actually a defined constant? The logic makes no sense. If the function exists, it is "Not found"?

Share this post


Link to post
Share on other sites

I don't think that would cause a syntax error. We need to see the preceding code.

Share this post


Link to post
Share on other sites

PHP saying there is a syntax error on line X doesn't necessarily mean that the error is actually on line X.  It could in fact be anywhere from line 1 through X.

The line PHP reports is just where PHP finally realized there is a problem.  With issues such as missing quotation marks or missing closing braces PHP will be able to continue parsing the source for quite a while before realizing something is amiss.  Most of the time, the line number reported gets you close, but if nothing appears wrong there you need to start back tracking until you figure it out.

Share this post


Link to post
Share on other sites
1 hour ago, gw1500se said:

I don't think that would cause a syntax error. We need to see the preceding code.

I know. That was just an "in addition to the problem". I agree the problem is the preceding code.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.