Jump to content

T_ELSE .. wrong line?


no_one

Recommended Posts

First, I've tried looking up other posts relating to t_else errors, but none of them helped.

 

I'm coding a site on my pc, and recently uploaded it all to my host to test it there.. It works perfectly fine on my pc, but on my host I get a T_ELSE error. Both have PHP5 installed.

 

Normally I wouldn't have too much of a problem finding what's wrong, but the error is showing up on a line in a class method on a variable definition. So, before I go through all my code line by line looking for a problem... I thought I'd ask

 

Posting code probably wont help, as it's split up in multiple files and putting it all together you'd have quite a few lines to look at leading up to this single line being pointed to. I could try though if needed, I'll give an example:

 

require_once("includestuff.php");

class someclass {
  /* ctor/dtor */

    public function method()
    {
            global gsomev;  // <- T_ELSE POINTS HERE

            // other code
    }
};

 

Is this common? Is there a way to get the actual line the php engine is actually having a problem with? ._.

 

Oh, final note, I tried moving things around a bit, and yes, the line changes but doesn't follow that 'global' or that method, so I'm guessing it has nothing to do w/ that piece of code.

 

Sorry if it's vague, I'd be more than happy to clear up any confusion if you have any ideas.

 

Thanks.

Link to comment
Share on other sites

The error line is - unfortunately - the script line where the interpreter finally choked and not the line where the code mistake exists which caused the error to finally manifest itself.

 

Here's a classic example:

 

01 <?

02 $somevar = "string variable;

03?>

04-15 <somehtml>

16 <?

17 $somevar2 = "another string variable";

18?>

The error will be reported on line 17 even though the real error is on line 02.

 

Somewhere you probably have an unterminated line ( no ; ) or a missing loop closure ( no } )

Link to comment
Share on other sites

Thank you. Yeah, that's what I've been thinking.. just not looking forward to going through 1k lines of code to find it.  :'(

 

I still don't get why the exact same code works on my pc setup but dies on the server. Same php versions and everything.  ???

Link to comment
Share on other sites

You can try a binary search by commenting out portions of code.  Start by commenting out around half your code, and see if the error is still there.  It's not guaranteed to work, but if it does it's O(log n) rather than O(n) time :)

 

One question, why do you have "global gsomev;" rather than "global $gsomev;" ?  If it's defined, then it doesn't need to be global.  If it's not defined, then it should have a dollar sign in front.

 

"Is this common? Is there a way to get the actual line the php engine is actually having a problem with? ._."  -- If php knew, it would tell you :)  Yes it's common unfortunately, but you'll learn the patterns.  Unterminated strings (like Andy's example), and missing closing braces are two very common patterns leading to errors on the wrong line.

 

Regarding why it works on your pc but not the host.. did you upload the latest version of every file?  Exactly the same?  md5 hashes can help here to have 100% confidence that you really are running the same code in both places.

Link to comment
Share on other sites

Aha, well the missing $ is a typo, it's there in my code.  And yeah, everything is the latest, it was the first upload to the server for testing.  All changes I've tried, and minor alterations have also been uploaded. Unless something is getting junked in the upload everything should be exactly the same.

I do the global thing for variables like an instance of my db class, etc. Not putting the the "global $db" would just give me errors relating to $db not being a valid variable and what-not. True, I could pass the db var every time the method is called, but I didn't want to bother with it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.