Tyrell Jamal
Tyrell Jamal

Reputation: 9

T_INCLUDE - Issue

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

Upvotes: 0

Views: 2751

Answers (2)

James
James

Reputation: 4783

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.

Upvotes: 2

zerkms
zerkms

Reputation: 254906

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.

Upvotes: 2

Related Questions