Laravel - syntax error, unexpected end of file - php

I have a website which works fine on host, but I'm currently trying to install it on localhost.
I've downloaded everything and configured to work on localhost - Database & URL.
The problem is this error:
Unhandled Exception
Message:
syntax error, unexpected end of file Location:
C:\Program Files (x86)\EasyPHP-12.1\www\laravel\view.php(386) :
eval()'d code on line 118
And I don't know what causes it. Any solutions?
P.S. I've setup in my windows' host file 127.0.0.1 myproject.dev.

There is an error within one of your views. If there is a more detailed stack trace it should show you details of a view, although the name will be an md5() string so it's a bit hard to find. You might want to delete all compiled Blade views in storage/views and let Blade re-compile the views.
If you still get the error then check your views to make sure you have all the proper closing tags, e.g., #endif or #endforeach
Always double check your views for any syntax errors.

I've run into this same error and I was able to fix it by adding spaces to the content within an inline if statement. For example:
Experienced error with:
#if( BLAH )Output#endif
Fixed error with:
#if( BLAH ) Output #endif
This may not be a problem in all cases and it was certainly difficult to track down but it is just one example that can cause this exact error.

A variation of this problem -- I had a php block, which I'd opened with
<? as opposed to <?php worked fine on LocalHost/MAMP, but gave the above error under Nginx/Ubuntu 16.04/PHP7 (both Laravel)

you should remove a character from view file. for example my character was "," (a comma) before some "#endfor". when i remove those worked!

Related

Laravel AdminLTE with Nwidart module menu option

I'm trying to call a module route from an AdminLTE submenu but it says:
syntax error, unexpected token ":", expecting "("
I'm writing at the top of file 'views/vendor/partials/sidebar/menu-item-link.blade.php' 2 lines but it is probably breaking with the first one:
#if( !isset($item['module']) || (Module::has($item['module']) )
And of course in the adminlte.php configuration file I add a 'module'=>'' to the menu item.
Am I doing something wrong?
thanks.
Hi and welcome to StackOverflow,
It seems there is an extra opening parenthesis in your code (the one before "Module").
Try with this instead:
#if( !isset($item['module']) || Module::has($item['module']) )
Thank you!
It's something I hate from PHP. I waste a lot of time with simple syntax errors.
It still doesn't work, but at least I found out it's not a Module system problem.

Fatal error : Cannot use [] for reading using smarty template

I am building a ticket support application, and the problem I am having since this weekend, is that when I head to the information page, I land onto the following error:
https://i.imgur.com/EzbxWe2.png
I looked this error up, and it seems to have to do with an array notation commonly seen as $arr = [$key][]
I have scanned my code at the lines of the error, and I cannot seem to trace why my page no longer shows. Underneath my Smarty template and the backend code running behind it:
Smarty Template: CallScreen.tpl
https://hastebin.com/pagubejesa.bash
CallScreen.php running on the background:
https://hastebin.com/ivezukahut.xml
RESOLVED
Error was that the local cache file was not updated, resulting in the error.

Pinpoint exact cause of PHP out of memory error ( ...it was var_dump() )

I've been getting the out of memory error occasionally for a few months now on an app that has been in continuous development & has about 20 users so far.
It didn't seem to have any negative repurcussions I could detect, but finally I have found the culprit.
I don't know how but I had a default 404 error view into which strange code had found its way, I'm not sure how I did that. This default 404 error view is called by the framework automatically if one uses findOrFail() and the db does not find a record. When a page was not available in my app (which is as it should be, as some content can be published/unpublished), this error view was triggering.
The weird code was:
<!-- <div><?php var_dump($exception); ?></div> -->
<div class="text">{{$exception->getMessage()}}</div>
Totally weird I know.
Firstly, the html comments, since it is a blade file, do not apply, so the var_dump was being called despite being 'commented out'.
So I replaced it with this:
{{ var_dump($exception) }}
and the out of memory error (and the 500 error in the browser) can be reliably reproduced.
Removing it, and the 404 view renders fine.
Replacing it with {{ dd($exception) }} works fine too - I get a render of the trace.
So, why does the var_dump line cause an out of memory error?
What should I do to investigate this further?
I'm on Laravel 5.3
This most likely happens because the content of the $exception variable is big. When you dump the variable, PHP will attempt to convert it to a string representation. This uses a lot of memory.
I don't see why you would need to output the entire exception object. You most likely just need the message (which you fetch by $exception->getMessage(). The rest is just backtrace and references to related objects and instances.

How do I use require_once()?

I create a PHP page with the following content:
<?php session_start(); ?>
<?php require_once(./classes/MaterialUtil.class.php);
$mUtil = new MaterialUtil();
?>
I put the MaterialUtil.class.php file in D:\xampp\htdocs\drupal\sites\all\themes\zeropoint\classes, but I get the following error message:
Parse error: syntax error, unexpected '.' in D:\xampp\htdocs\drupal\modules\php\php.module(80) : eval()'d code on line 7
Could you please tell me what I do wrong?
The error is caused from the fact you didn't use a string for the filename, and PHP understood the dot as being the concatenation operator; as such, because there wasn't any value before the operator, PHP gave you an error saying it found the concatenation operator in the wrong place.
As kalabro said, the correct code is the following one:
<?php session_start(); ?>
<?php require_once('./classes/MaterialUtil.class.php');
$mUtil = new MaterialUtil();
?>
This is the part of the answer that is not strictly related to Drupal.
What you are doing is not what I would suggest to do, for two reasons:
You are putting the "classes" directory in the wrong place. Those files are not related to the theme being enabled, but they are related to the page being viewed. Even if you have a single theme, and users are not allowed to select a theme for themselves, it still wrong to put those files in a theme directory.
Putting the files in the directory containing a theme, which will needs to be updated when a new version is available, could cause you to lose the additional files you added, if you are not careful.
Executing PHP through eval() to, e.g., get content to show in a node is not something that you should do. This is because:
As you have used the PHP filter for the node, the node becomes only editable to a restricted group of users. (I would not suggest to allow untrusted users to use PHP as input format)
When you have PHP code that you need to execute, it is always better to create a custom module that is enabled for the site.
If you were trying to include a PHP file from inside a module, then you should use module_load_include(), instead of require_once(), as already suggested by marcvangend.
XAMP server does not run on windows file system format. You must write your file location like localhost/xyz/abc ..

Unbelievable PHP script won't echo out string

I have a test.php script which contains this:
<?php echo 'test'; ?>
When I point to it via my browser, it works and prints out "test" as expected.
I have another script which I am trying to test but however, it is ignoring all my echos! I thought I would put an echo right at the top as this will surely work, but when I get to this script via POST request from a form. It does not even echo out what is at the top of the line:
<?php echo 'START START START';
error_reporting(E_ALL);
I even point to from my browser and still no output?
What the hell is going on?
Update
The error log shows this :
PHP Parse error: syntax error, unexpected T_ECHO in /var/www/tester/convertor.php
But the echo is at the top of the line. I am going to set diaplay errors.
You have a parse error, so the script isn't even executed. So it's expected that it won't output anything.
The parse error can be for any echo in the script. It may be because of an "echo" statement after a line missing a semicolon, for example.
Things to try:
Check your error log
Check the headers (is it coming back 404?)
Make sure you view-source: don't just look in the browser
Delete everything except the echo. If it works, add things back a bit at a time until it breaks.
Load your script in a hex editor and make sure there aren't any weird characters in there
Are you including this file from another file? If so, check the other file too. Watch out for output buffering.
Put exit; after the echo start start start and see if that works. Look in the apache error log for clues. Comment out the rest of the PHP code in the file and see if it works then...
UPDATE
I have had this when copy pasting white space from a browser sometimes - e.g. copy/pasting some code from a web page. Sometimes weird control characters get embedded invisibly in the white space, and I find that deleting the whitespace and re-entering it fixes it. Did you copy paste anything into this file?
Are you hosting this page on a server with PHP installed?
If you just have a .php file on your hard drive somewhere and open it in a web browser, it won't work. You need to be running a web server with PHP extensions and access the file using the HTTP or HTTPS protocols.
On a similar note to this i have seen alot of scripts throw errors like this when they have come from developers on windows (i'm on linux).
I have to go to the start of the php file and hit delete a couple of times to get rid of some invisible characters before the script will run.
You're missing the ending ?>
<?php
echo 'START START START';
error_reporting(E_ALL);
?>

Categories