OK, in a case like this, where it's unclear where the error is coming from, I'd go back to the most primitive method of debugging possible.
go line by line and add in
echo 'test - passed';
exit;
then save you're file, upload it and see if you get the error or you see 'test - passed'.
see how far into your code you can get, before you start getting the error. When you get the error, you'll be able to tell which bit of code is giving you the issue.
Like I said, it's primitive but it's a good way to get some clarity on which part of the code you're having issues with.