0

I'm currently having the issue of

Parse error: syntax error, unexpected T_INCLUDE in /home1/defcon2/public_html/usercp/index.php on line 13

Here is the code up to that point:

<?php
/* [snip] */
require_once(__DIR__ . "/recources/utils.class.php")
include(__DIR__ . "/resources/pagehead.php"); // line 13

The file is in the right location, and I'm using PHPMyAdmin 3.5.5

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
Tyrell Jamal
  • 9
  • 1
  • 1

2 Answers2

2

Ok, so if this is your code as you provided, then the issue is simple:

require_once(__DIR__."/recources/utils.class.php") //<-- no semi colon
include(__DIR__."/resources/pagehead.php");

You missed a semi colon at the end of the require_once line.

PHP error reporting is precise in what it states. PHP doesn't lie, even if the actual issue in your code is not the error and/or line PHP has stated in the error.

"unexpected" anything in PHP errors is usually straight cut, in that it was expecting something before whatever is mentioned in the error. In this case, unexpected 'unexpected T_INCLUDE' your line above was missing a semi-colon.

Adding to the whole scenario, and that you just need to include a file from a specific location, is __DIR__ what you need? This will return the directory of the file, and if __DIR__ is used inside an include file, the directory of the included file is returned.
If your PHP version is too old and cannot be updated, you'll have to explicitly list the full path.

Alternatively, if you have a bootstrap type file (included in all scripts) you could define something there, if it's worthwhile and used often enough.

James
  • 4,644
  • 5
  • 37
  • 48
  • it was posted in the comment by OP and in their original question, edited by echo_me – James Sep 22 '13 at 00:30
  • double underscore is a bold in markdown. so `__DIR__` becomes __DIR__ – zerkms Sep 22 '13 at 00:30
  • @James . thats actually didnt do anything, it ruined it further lol Warning: require_once(__DIR__/recources/utils.class.php) [function.require-once]: failed to open stream: No such file or directory in /home1/defcon2/public_html/usercp/index.php on line 12 Fatal error: require_once() [function.require]: Failed opening required '__DIR__/recources/utils.class.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home1/../public_html/usercp/index.php on line 12 – Tyrell Jamal Sep 22 '13 at 00:31
  • ok, look at zerkms' answer and if your PHP versions is before `__DIR__` it wont work. Also, is "recources" the correct folder name? – James Sep 22 '13 at 00:37
  • No problem. I answered the original question which fixed the code, and from there it revealed an issue further down the line. This sometimes happens. – James Sep 22 '13 at 00:44
  • "which fixed the code" --- to be completely honest - it was fixed in the comments 3 minutes before your answer. – zerkms Sep 22 '13 at 00:45
  • Not sure what your point is. It took me a few mins to write a bit of generic info on PHP errors to help the OP/other people troubleshoot for themselves in the future. The comments are not answers, either. – James Sep 22 '13 at 00:47
  • My point was "I answered the original question **which fixed the code**" - is not entirely true. OP fixed their code themselves, before your answer. Irrespective to the fact that your answer is correct, it wasn't the one that gave OP the original hint. – zerkms Sep 22 '13 at 00:48
  • What is the issue here? I wasn't claiming I went to his house and typed in the fixes. I just meant what I put in the answer was the fix and from that other issues ensued. If we're going to split hairs, your answer is not an answer to the original question. It helps a lot, however, so I felt no need to comment or downvote (apart from pointing it out now). chill – James Sep 22 '13 at 00:52
  • "so I felt no need to comment or downvote" --- lol, it would be very nice if you downvoted the correct answer. Anyway, I'm standing at my point, your wording is incorrect. – zerkms Sep 22 '13 at 00:54
  • No, the correct answer to the question was a missing semi colon. pure and simple. We both helped out here, the OP has their issue resolved, so what is the big problem? If you wish to continue to discuss, perhaps take it to meta. – James Sep 22 '13 at 00:56
  • "so what is the big problem" --- it's about timing. It makes no sense to say "which fixed the code" when at the moment you posted your answer the code has already been fixed. It doesn't matter if the answer is correct or not, but it was just too late (to say it fixed something) – zerkms Sep 22 '13 at 00:57
  • I knew the issue was the line before the code in the question, I presumed it would likely be a missing semi colon. **I** asked the OP to provide the code above the one referenced in the error. When they did I then *knew* rather than *presuming* it was a missing semi colon so I answered. It took you seconds to write your comment, whereas I spent some time to write a bit more info about PHP errors/that specific error & provided code to show where the issue is. The fact another issue arose having fixed this one does not mean your answer is correct for the *question*. It helped fix another issue. – James Sep 22 '13 at 01:13
2

Failed opening required '__DIR__/recources/utils.class.php is caused by using php older than 5.3.0, which the __DIR__ introduced first.

You could "fix" it by replacing __DIR__ with dirname(__FILE__) but there is a chance that the code isn't just compatible with ancient php versions.

zerkms
  • 249,484
  • 69
  • 436
  • 539
  • You are literally my life save, I appreciate the help! that was the issue! :) – Tyrell Jamal Sep 22 '13 at 00:42
  • 1
    @Tyrell Jamal: you're warned though, that there is a chance there are some other issues caused by using not suitable php version – zerkms Sep 22 '13 at 00:43