no_one Posted June 27, 2007 Share Posted June 27, 2007 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. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted June 27, 2007 Share Posted June 27, 2007 Look at the very last line: }; Why do you have a semicolon there? Try removing it and see if the error goes away. Quote Link to comment Share on other sites More sharing options...
no_one Posted June 28, 2007 Author Share Posted June 28, 2007 You think? Never had any problems with that before.. kind of a cross-over since my main language is C++.. new to php :s. I'll give it a try, thank you for the response. [edit] - tried, and failed. Quote Link to comment Share on other sites More sharing options...
AndyB Posted June 28, 2007 Share Posted June 28, 2007 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 } ) Quote Link to comment Share on other sites More sharing options...
no_one Posted June 28, 2007 Author Share Posted June 28, 2007 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. ??? Quote Link to comment Share on other sites More sharing options...
btherl Posted June 28, 2007 Share Posted June 28, 2007 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. Quote Link to comment Share on other sites More sharing options...
no_one Posted June 28, 2007 Author Share Posted June 28, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.