"Parse error: syntax error, unexpected variable (T_VARIABLE)"
When ? show some code related to your controller, view and the error log.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi
After upgrading my Xampp to PHP 7 i noticed that laravel shows blank error pages. The log still shows errors as normal. Funny thing, if i put a random word into a controller, the error is shown but when i put it into a trait then the error page is blank. Also, other errors in controller are not shown. Only error that is shown (that i have found) is "Parse error: syntax error, unexpected variable (T_VARIABLE)" when i put random word into controller.
How can i fix it?
"Parse error: syntax error, unexpected variable (T_VARIABLE)"
When ? show some code related to your controller, view and the error log.
check your logs? laravel, or xampp. to see what error is being reported and what lines
@premsaurav @shez1983 The problem is not the errors, but the fact that error pages do not appear. I created errors myself to test if it shows them. My old code, the one i copied from old xampp worked fine. The problem is related to moving project to new xampp installation with PHP 7.
When there is no errors, the page itself displays fine without problems.
@Dreamer Lets debug, see if it reaches the handler
// App\Exceptions.php
public function render($request, Exception $e)
{
dd($e);
return parent::render($request, $e);
}
Yeah, it works. I saw the error:
FatalThrowableError {#332 ▼
#message: "Fatal error: Call to undefined function App\Http\Controllers\Module\jdhf()"
#code: 0
#file: "C:\xampp\htdocs\app\Http\Controllers\Module\DashboardController.php"
#line: 29
#severity: E_ERROR
-trace: {▶}
}
next step ...
public function render($request, Exception $e)
{
$response = parent::render($request, $e);
dd($response->content()); // to see if content is being set
}
@premsaurav Yes, html content is there and it seems to be full error page :)
last step ... (conditional)
public function render($request, Exception $e)
{
$response = parent::render($request, $e);
$response->setStatusCode(200);
return $response;
}
If it shows now, then it has nothing to do with laravel, may be some php 7 / xammp setting. Will try to figure out and let you know in that case.
Thanks for your time. Yes, it shows the error page. What it could be related to? I could google it... but right now i have no idea how to begin searching.
One thing to note here too. If i open source of the blank error page, it shows very basic html... like, html, head, body tags only.
@Dreamer Really don't have much idea as of now, may could play around with the status codes and check where you stop seeing the response. This might help to pinpoint some strange behavior.
@premsaurav Thanks. Will check it out.
If anyone else has any tips, feel free to share!
Okay, i now tested all official status codes from this page https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
These are the ones that showed blank error page:
101,102,103
304
400,408,411,413,414
500, 501, 503
@Dreamer No worries, checking now, meanwhile, few details, which os (permission issues if any ?)
@premsaurav Thank you!
I am using Windows 10, downloaded latest Xampp yesterday. Also, just in case, i made a new laravel project and checked if it has the same problem. Yes, the problem was on new project too.
Since i am in Windows there cant be any file permission errors...?
I could also, just in case, reinstall xampp, if that could help.
Oh, and if this makes any difference, i am using virtual host to display my project, but, the new test project i accessed without virtual host and they both had the same problem. So, i doubt that is what causes it.
(Tested clean xampp install it did not help)
@premsaurav Any new insights about the problem? Just asking, im not in a hurry.
Hey, tried this on mac works fine, yet to try on windows with PHP 7.
why dont you try homestead or vagrant? or try WAMP instead of XAMP?
I just ran into a similar issue, in PHP7 they have replaced the Fatal Errors with Exceptions of type Error: http://php.net/manual/en/language.errors.php7.php
This gave us a couple of uncatchable exceptions in the exception handler, you might want to test by removing the typehints in the error handler and check what is being written to the logs
@lostdreamer_nl How do i do that?
@premsaurav Any new thoughts on this? Just started a new project and had the same exact issue... Applied your temporary fix for now.
@shez1983 Will try WAMP then...
in app/Exceptions/Handler.php, remove the typehints
public function report(Exception $e)
{
parent::report($e);
}
public function render($request, Exception $e)
{
return parent::render($request, $e);
}
Becomes
public function report($e)
{
parent::report($e);
}
public function render($request, $e)
{
return parent::render($request, $e);
}
Removing the 'Exception' typehint will let the FatalErrors be caught as well (they do not extend the Exception class) showing you the actual errors
Good luck
Thanks @lostdreamer_nl
Ill try it out.
Please or to participate in this conversation.