codeigniter php code on xampp works but not on ubuntu - php

I have this code that works perfectly on my local xampp (PHP 5.5.24) but gives error on ubuntu (PHP 5.5.9-1ubuntu4.14):
Parse error: syntax error, unexpected '}' in /var/www/html/maybright/application/views/admin/components/edit_user.php on line 179
A PHP Error was encountered
Severity: Parsing Error
Message: syntax error, unexpected '}'
Filename: components/edit_user.php
Line Number: 179
<p>Backtrace:</p>
I know it is parse error, so I am attaching the file as well. The controller has this
$userDetails = $this->maybright->GetUserDetails($user_id);
$userDetails = json_decode(json_encode($userDetails), FALSE);
$content['user_id'] = $user_id;
$content['User_details'] = $userDetails->response;
$content['subview']="edit_user";
$this->load->view('admin/_main_layout', $content);
The view is in gist at https://gist.github.com/vishwakarma09/27fc2ca1ec33d8eca05d47c878141a32
you can view it as raw and open in notepad++ for proper indentation.
$userDetails is this json response:
{"status":"SUCCESS","id":25,"message":null,"responseSize":1,"response":{"id":25,"hash":null,"name":"Arindam Nath","firstName":null,"middleName":null,"lastName":null,"email":"strider2023#gmail.com","phoneNumber":"9874381131","accountType":"USER","gender":"MALE","dob":630143205000,"maritalStatus":"SINGLE","workStatus":"SALARIED","residentialStatus":"RENTAL","deviceData":null,"userImage":"https:\/\/s3-ap-southeast-1.amazonaws.com\/mbv-pokket\/user-images\/user_profile_25_userImage_1459410437667.jpg","referralCode":null,"fatherName":"Aroon Nath","gcmId":null,"roleType":"LEND","rating":null,"defaults":null,"userLocationDatas":[{"id":70,"userId":25,"address":"House No. 34, Chooliemedu","city":"Chennai","state":"Tamil Nadu","country":"India","pincode":600034,"type":"HOME","isVerified":true},{"id":50,"userId":25,"address":"Chatterjee Bagan","city":"Hooghly","state":"West Bengal","country":"India","pincode":712102,"type":"CURRENT","isVerified":true},{"id":49,"userId":25,"address":"Chatterjee Bagan, ","city":"Hooghly","state":"West Bengal","country":"India","pincode":712102,"type":"HOME","isVerified":true}],"userKYCDatas":[{"id":12,"userId":25,"type":"PASSPORT","kycId":"ASD6Q133","imageUrl":"https:\/\/s3-ap-southeast-1.amazonaws.com\/mbv-pokket\/user-images\/user_kyc_25_kycImg_1459526858473.jpg","isVerified":true},{"id":10,"userId":25,"type":"PAN","kycId":"AHIPN123456","imageUrl":"https:\/\/s3-ap-southeast-1.amazonaws.com\/mbv-pokket\/user-images\/user_kyc_25_kycImg_1458574318698.jpg","isVerified":true}],"userEducationDatas":[{"id":11,"userId":25,"institutionName":"ICAT","degreeType":"BACHELORS","degreeCategoryName":"Game Programming","description":"Game programming","startDate":1187019048000,"endDate":1280158262000,"city":"Chennai","country":"India","state":"Tamil Nadu","pincode":600034,"score":null,"reportUrl":null,"isVerified":true}]}}
UPDATE
I have updated controller view and current deployed URL in comments. Please check.

Using my comment as an answer as it helped fix the issue:
The problem is that the close bracket in question is the close to an opening if-statement on line 123. This statement is opened by the following code:
<? if(isset($User_details->userLocationDatas)){ ?>
This is using the PHP short tags option (doesn't start <?php) The windows machine the development is taking place on allows this, but the Ubuntu server doesn't. As a result, the opening if statement is treated as HTML by the server, and the correctly formed <?php }?> is seen as not needed; hence the error.
There's a couple of ways I can think of to help avoid this in future:
Never use short tags for PHP in your code. Either use <?php or <?= as appropriate. The former is more readable and widely used
Where possible, develop on an environment which is configured the same (or as close as possible) to the environment it is going to be deployed on, so these issues are caught early.

Related

A weird PHP file in which any instruction is a syntax error

I have a Web application in PHP which when / (or something else) of it is opened in a browser displays the following error in the browser: Parse error: syntax error, unexpected 'require_once' (T_REQUIRE_ONCE) in /var/www/n_environment.php on line 3. The file n_environment.php is loaded with require_once 'n_environment.php'; in index.php. And also from different places. It contains just comments, calls to define (unconditional or guarded by if (!defined) and two assignments of arrays of strings to variables.
I thought maybe it's (indirectly) in a class but not in a method, which indeed PHP prohibits for require_once, but apparently that's not the problem here. If I put anything else as the first instruction, e.g. echo or an assignment, a similar error (with a different offending token) results.
If I comment out everything in the file except the initial <?php, the error changes to unexpected end of file.
And if I also remove the <?php, what I get in the browser is the file content (block comment with code inside) with â instead of new lines.
What are the possible, most likely reasons for such behaviour? And how to fix it?

Access a PHP-object with dollar-sign as node name - Parse error: syntax error, (T_CONSTANT_ENCAPSED_STRING)

Before we get into this, I've found the exact issue i'm dealing with, however the solution does not fix my issue.
Access a PHP-object with dollar-sign as node name
Here is the relevant PHP code.
$user = 'officialtiesto';
$artist_json = file_get_contents('https://gdata.youtube.com/feeds/api/users/' . $user . '?alt=json');
$artist_object = json_decode($artist_json, FALSE);
var_dump($artist_object->'yt$googlePlusUser');
I have also tried this:
var_dump($artist_object->{'yt$googlePlusUser'})
Both present me with the following error:
Parse error: syntax error, unexpected ''yt$googlePlusUser''
(T_CONSTANT_ENCAPSED_STRING), expecting identifier (T_STRING) or
variable (T_VARIABLE) or '{' or '$' in
C:\Users\astark\Desktop\charts\youtube.php on line 22
I read somewhere that having an out of date version of PHP can cause issues similar to this so i've included a link to a JSBin (http://jsbin.com/yahevoyo) with the specs of the XAMPP setup i'm running. Pretty stumped here on this one and not sure if its just the late night getting to me, or a larger problem. Please advise.
First, there is no yt$googlePlusUser, it's yt$googlePlusUserId.
Then you've missed one level. Instead of
$artist_object->{'yt$googlePlusUserId'}
use
$artist_object->entry->{'yt$googlePlusUserId'}
And finally, as a bonus, to get the ID:
$artist_object->entry->{'yt$googlePlusUserId'}->{'$t'}
Alternatively as it's written in the answer to the question you referred to you could convert the JSON object to an array using $artist = json_decode($artist_json, true) and access the property as $artist['entry']['yt$googlePlusUserId']['$t].
Update:
Regarding PHP version, etc. you seem to have 5.4.19 installed, I've tested the above on 5.4.0 and it works.

php define statement failing while moving php app from linux system to one running windows 7 with wamp

I'm setting up a dev environment to work on a php site.
i've copied all my source code onto a windows 7 box running wamp.
I'm trying to update all the paths to reflect the correct locations on my dev box.
But I'm having probem with some of my define statements. For example, I have the following code:
define ('DOCUMENT_ROOT', 'c:\wamp\www\myapplicationname\members\');
define ('DB_LOG', 'c:\wamp\www\myapplicationname\members\log\db');
define ('ERROR_LOG', 'c:\wamp\www\myapplicationname\members\log\errors');
When I try to run site site, I get the following error message:
Parse error: syntax error, unexpected T_STRING in
C:\wamp\www\myapplicationname\members\includes\init.php on line 39
Line 39 is the second define statement I listed above. I can tell there's a problem because the syntax highlighting for the second line is not working. It doesn't recognize the "define" statement.
If I change the first line to look like:
define ('DOCUMENT_ROOT', 'c:\wamp\www\myapplicationname\members\\');
then the highlighting works again, but ofcourse, the path is wrong.
Can you tell me what I'm missing ?
EDIT 1
I've tried to change it to:
'define ('DOCUMENT_ROOT', 'c:\wamp\www\myapplicationname\members\'');
but then later in the code when we're appending to DOCUMENT_ROOT like so,
require_once DOCUMENT_ROOT.'\inc\exception.class.php';
i get the following error:
Warning: require_once(c:\wamp\www\myapplicationname\members'\inc\exception.class.php) [function.require-once]: failed to open stream:
SO code highlighting shows the problem clearly: \ is a escape character and it's escaping the following character. ' isn't interpreted as string end, but as a ' character in that string. Then your string spans over to the next line, which is not allowed and PHP throws an error.
If you want to use \ in strings, you need to type \\ - the first one will escape the second one:
define ('DOCUMENT_ROOT', 'c:\\wamp\\www\\myapplicationname\\members\\');
define ('DB_LOG', 'c:\\wamp\\www\\myapplicationname\\members\\log\\db');
define ('ERROR_LOG', 'c:\\wamp\\www\\myapplicationname\\members\\log\\errors');
You want to escape all backslashes, because they are special characters in PHP:
define ('DOCUMENT_ROOT', 'c:\\wamp\\www\\myapplicationname\\members\\');
define ('DB_LOG', 'c:\\wamp\\www\\myapplicationname\\members\\log\\db');
define ('ERROR_LOG', 'c:\\wamp\www\\myapplicationname\\members\\log\\errors');

Parse error: syntax error, unexpected T_SL on line 23

I am getting this error:
Parse error: syntax error, unexpected
T_SL on line 23
Here is line 23:
$selectorder = <<<ORDER
Here it is in context:
$grid->setUrl('myfirstgrid.php');
$selectorder = <<<ORDER
function(rowid, selected)
{
if(rowid != null) {
alert("selected: "+rowid);
}
}
ORDER;
$grid->setGridEvent('onSelectRow', $selectorder);
What is causing this error?
I personally don't know what <<< does and have never used it, I got it from a tutorial. I tried to google it, but you can't google characters like that :(
Check for whitespace after <<<ORDER. There should be no blank characters.
<<< is for heredoc: See manual
Make sure that there is no SPACE/INDENTATION before ending ORDER;
PHP Heredoc does not get on well with the % symbol, and the following also causes Parse error: syntax error, unexpected T_SL:
<?php
$var=<<<%%SHRUBBERY%%
Nih!
%%SHRUBBERY%%;
?>
Also make sure that you have 3 '<<<'. Omitting one will throw this error. Also if your using NOWDOCs, make sure your hosting provider has php 5.3 installed. Plus if your php environment is below 5.3, do not use double quotes or single quotes.
It's called "Heredoc syntax", and it lets you specify large strings without using quotes. In this case, it looks like you're using it to put JavaScript code into a variable. Since you started the string with <<<ORDER, you should be able to finish it with ORDER;, as you have — but you need to make sure that ORDER; occurs at the start of a line, with no whitespace before it.

T_STRING error on line that just says <?php

So I'm writing a script in codeigniter, and I get the following error message:
Parse error: syntax error, unexpected T_STRING in /home/globalar/public_html/givinghusband.com/system/application/controllers/sizes.php on line 1
the only problem: the only thing on that line is this:
<?php
So I'm quite mysterified as to what's going on here? Have I typed PHP wrong or what?
There could be a problem with your editor when it updated the file. I just had this problem and the editor removed all line breaks.
If you are uncertain try opening your php file in another editor or use the Cpanel file manager to take a peak.
Or you may have an unterminated quote or statement on some previous line without an ending semicolon (;) . Check all files that are included before this one.
a bare <?php in the file leads to a parse error in php (don't ask). Try adding a whitespace or a newline after it
Sorry.A bit late but might helpful for others.Just looked at your question.Just use
<?
?>
instead of :
<?php
?>
and remove whitespaces/line breaks between your php open tag and class name .It will resolve this conflict.Ta

Categories