PHP Unexpected end of file confusion

Hi all, I’m really struggling with an unexpected end of file error that I am receiving.

For starters, the code is pretty lengthy so I’ll post a link to it rather than submitting it here: https://github.com/csev/tsugi/blob/master/lib/lms_lib.php

So this is part of a course I am taking, and the intent is to install and later utilize tsugi, but this one file is giving me issues. It does not appear as though anyone else received this error when running the file, and after running the code through an IDE I couldn’t spot any obvious bracketing issues. Is there something I’m possibly missing?

I appreciate any help you can give! Thanks for your time.

Well, it appears your error is in line #1514

(I think !)

So, this is:
HEARTBEAT_URL = ‘<?php echo(sessionize($CFG->wwwroot.'/core/util/heartbeat.php')); ?>’;

As you see, you are displaying HTML and stick in a PHP line. Whis is fine. BUT, you use single quotes to
identify the OUTSIDE of the data in the PHP area in the HTML line.
Now, INSIDE the PHP, it also uses the single quotes…

I hope that is is… Good luck…

So then should the change be:

HEARTBEAT_URL = “<?php echo(sessionize($CFG->wwwroot.'/core/util/heartbeat.php')); ?>”;

Is that right? It doesn’t appear to have worked.

Well, that is one thing. Yes, I think the new version is correct.

Do you actually get an error line? Do you have the PHP error reporting set to all errors?
Perhaps you need to do that first and maybe it will give you more information.

Add these two lines at the beginning of the page, after any “session_start()” line if it is there…

[php] error_reporting(E_ALL);
ini_set(“display_errors”, 1);[/php]

I edited the first 4 lines such that it looks like this:
[php]<?php

require_once “lti_util.php”;
error_reporting(E_ALL);[/php]

I assume that it should display all errors in that case (This is clearly all several levels of knowledge over mine, this file was supposed to work as-is).

The error I am receiving with the added error reporting is this:

Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\tsugi\lib\lms_lib.php on line 1692.

Which is the same as I had been getting before, but simply line 1691.

Sorry, didn’t notice the second post, I made your change and its outputting the same line.

The file you posted on the other site with the long listing only goes to 1688.

So, I will assume that it is not showing the INCLUDED files.

Post here lines 1680 to 1700 or so. Then, I can match up those to what you posted on the other site…

[php]

  • Login

  • <?php } ?>



    <?
    }
    }

    $OUTPUT = new default_renderer();

    // No trailer

    [/php]

    I think the line # difference is simply my additions and a few spacing lines.

    Hold on, I have the error narrowed in…

    Okay, I narrowed the error down to this area. It is the function “do_analytics”. Inside of that function, you have some Javascript code in it. If you remove the Javascript code, the file passes okay.

    So, it is something in this routine:
    [php]

    var _gaq = _gaq || []; _gaq.push(['_setAccount', '<?php echo($CFG->analytics_key); ?>']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; // ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); [/php] So, I think it is the (function() line. If you remove this section, it passes just fine. Not sure why the (function part is there. If it is a function to run on the page load-up, it should be higher up in the page. Not sure on this. You might want to check the original code and see if this section was changed at all...

    I don’t understand… I’m receiving the same error after removing that section. I know it deviates from the strict error message, but could there be some sort of xampp permission issue occurring? I feel like the error message may be deviating attention from a more basic problem somewhere, since it is so utterly persistent

    Well, on my system, I remove those lines and I no longer get any errors showing…

    I found this same code (the code I removed while testing) online and it was similar to your version enough to think that your code is okay. So, I would guess that there is something feeding the data somewhere that is causing something to be passed into the page.

    So, I think you need to reduce the page to smaller sections and debug each of them on their own.
    The current 1700 lines plus the included files which I can not see make up a huge system. The live
    HTML code is mixed in with the functions. Some of the functions create HTML code and some JS scripts
    create HTML code, too. So, this is a very complicated system. Perhaps you remember what you changed
    before when it was working correctly. Or, perhaps you can restart over with the original template you
    were using.

    Sorry, not much help. Still trying to understand what all of these functions do… Lots of them to study…

    As a follow up, I’ve found the error and am frustrated at how simple it was:

    The end of the file looked like this: [php] <?php } else { ?>

  • Login

  • <?php } ?>



    <?
    }
    }

    $OUTPUT = new default_renderer();

    // No trailer
    [/php]

    My php.ini did not allow for the short hand version of <?php, meaning when it was changed to:

    [php] <?php } else { ?>

  • Login

  • <?php } ?>



    <?php
    }
    }

    $OUTPUT = new default_renderer();

    // No trailer
    [/php]

    it worked just fine. So, word of caution for anyone else getting end of file errors, try testing with all instances of “<?” changed to “<?php”. Figured I’d post in case someone gets something similar.

    Thank you for posting that update. I am very sorry I did not see that or I would have mentioned it.

    Wow, very nice catch. I hate little things like that. But, it is the life of programming… Again, nice catch!

    Hmmmm, wonder why the removal of the javascript code would clear that error out?
    Odd!

    Sponsor our Newsletter | Privacy Policy | Terms of Service