Reputation: 25928
I have a very weird error in my Laravel project. Some code in my Blade view file runs perfectly on the server but fails on my local project VM.
The simple code is:
<?$class = 'abc';?>
<p><?=$class?></p> /* My local project fails here */
On my local Laravel project I get the error:
exception 'ErrorException' with message 'Undefined variable: class
Why the difference? I'm really curious to know why this would work on the server but fail locally.
Server Setup:
Laravel Framework version 5.2.45
PHP 5.6.30 (cli) (built: Mar 11 2017 08:42:18)
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
Local Setup:
Laravel Framework version 5.2.45
PHP 5.6.15-1+deb.sury.org~trusty+1 (cli)
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
with Xdebug v2.3.2, Copyright (c) 2002-2015, by Derick Rethans
with blackfire v1.6.0, https://blackfire.io, by Blackfireio Inc.
Edit: After Steve's advice. If I change the code to the below it works. Whats going on?
<?php $class = 'abc';?>
<p><?=$class?></p
Upvotes: 1
Views: 692
Reputation: 57
I had the same issue and finally I discovered the issue after half day of work. check the component folder should start with uppercase!
Upvotes: 0
Reputation: 20469
To expand my comment into an answer, <?$class = 'abc';?>
could be the issue, <?
is a short open tag, which are not enabled by default (not to be confused with <?=
which is a short echo tag, and is enabled by default).
If this is the case, then you should edit your php.ini with:
short_open_tag = On
to match your live environment, or replace all instances of <?
(thats including the trailing space so you dont catch the perfectly valid <?=
) with <?php
throughout the project.
generally short open tags are disabled because they can cause issues reading xml, so i would personally opt for the second option.
Either way be consistent.
Upvotes: 2
Reputation: 1268
May be you cannot use short tag <?
on your local environment. Check short_open_tag
value in your local php.ini
file.
From documentation: PHP also allows for short open tag
http://php.net/manual/en/language.basic-syntax.phptags.php
Or just use
<?php $class = 'abc'; ?>
instead of
<?$ $class = 'abc'; ?>
Upvotes: 1