I've gotten my site to run perfectly on my local machine. However, migrating to production, I get roadblocked by "Unexpected T_FUNCTION ..." error.
I've stripped everything prior to the following code and still get the error reported for line 3. I just can't figure this out.
<?php
// Auth Check.
$authCheck = function() use ($app) { <---- Line 3
You are getting :
Parse error: syntax error, unexpected T_FUNCTION in [...][...] on line 4
becasue you are using PHP version less than PHP 5.3.0 upgrade your php or try using globals
PHP 5.3.0+
$app = "Hello Wolrd";
$authCheck = function () use($app) {
echo $app;
};
$authCheck();
Below PHP 5.3.0
$app = "Hello Wolrd";
$authCheck = function () {
global $app;
echo $app;
};
$authCheck();
Both would output
Hello Wolrd
Related
I wrote a simple function to execute in php interactive way:
php -a
php > function mytest() {
php { $tmpstr='yyy';
php { $tmpstr=$tmpstr."xxxx";
php { echo $tmpstr;
php { }
PHP Parse error: syntax error, unexpected '$tmpstr' (T_VARIABLE) in php shell code on line 3
The source code:
function mytest() {
$tmpstr='yyy';
$tmpstr=$tmpstr."xxxx";
echo $tmpstr;
}
I can't find what is wrong with this simple function.
I am practicing with facebook PHP api
when i am trying to make a login function
here comes out this warnning
syntax error, unexpected T_OBJECT_OPERATOR in /home/u528851895/public_html/Desktap/facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookResponse.php on line 137
but it's ok when i use mamp localhost
here's line 136~138 in FacebookResponse.php:
public function getGraphObject($type = 'Facebook\GraphObject') {
return (new GraphObject($this->responseData))->cast($type);
}
Upgrade your php version or do something like this
public function getGraphObject($type = 'Facebook\GraphObject') {
$obj = new GraphObject($this->responseData);
return $obj->cast($type);
}
i am trying to upload my codeigniter website on 000webhost server . but its giving me a syntax error
syntax error, unexpected '[', expecting ')' in
/home/a4703701/public_html/application/controllers/update.php
but its working correct on localhost.
the error is in model my model is
public function user($id=NULL)
{
if($id=='')
{
$q = $this->db->get('user');
if($q->num_rows()>0)
{
return $q;
}
}
else
{
$q = $this->db->get_where('user',['id'=>$id]);
if($q->num_rows()>0)
{
return $q->row();
}
}
}
any idea how to remove this error ?
You're almost certainly not running PHP 5.4 or newer but are trying to use syntax only available in those versions.
['id'=>$id]
is shorthand array syntax and was introduced in PHP 5.4. You need to replace it with:
array('id'=>$id)
to be backwards compatible with prior PHP versions.
The code is
// Get singleton (first value from row with single value)
static function singleton($arg, $params = false) {
return pg_fetch_row(SQL($arg, $params))[0];
}
The error message is
2014-02-19 12:54:23: (mod_fastcgi.c.2701) FastCGI-stderr: PHP message: PHP Parse error: syntax error, unexpected '[' in /var/www/blockexplorer.com/htdocs/includes/sql.inc on line 69
I think there is a config that can fix it.
This depends on PHP version you are using. If you are using PHP 5.4 or above then your code will not give error otherwise you will have to store the result in a variable and use it.
Reference : PHP 5.4
Look for "Array Dereferencing" here.
Put the result of the function in a variable
static function singleton($arg, $params = false) {
$foo = pg_fetch_row(SQL($arg, $params));
return $foo[0];
}
PHP does not support anonymous arrays. Use an named array instead:
static function singleton($arg, $params = false) {
$row=pg_fetch_row(SQL($arg, $params));
return $row[0];
}
I'm having trouble with Soundcloud.php on my server. Although it runs just fine on my MAMP installation. Basically my test page won't load and an error is logged declaring a problem in Soundcloud.php:
[03-Apr-2012 03:50:57] PHP Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /home2/mysite/public_html/mysubdomain/Soundcloud.php on line 685
the test code is fine - here it is for reference:
<?php
require 'Soundcloud.php';
$soundcloud = new Services_Soundcloud('Client_ID','Client_Secret', 'Redirect_URI');
try {
$info = json_decode($soundcloud->get('tracks', array('user_id' => 'blumarten')), true);
print_r($info);
}
catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
exit($e->getMessage());
}
I just had the account upgraded to PHP 5.3 but the error still occurs, any ideas?
SoundCloud PHP API and documentation are very poor and buggy at the moment , hopefully will get better.
Replace this code around line 720
$postData = array_map(function ($track) {
return 'playlist[tracks][][id]=' . $track;
}, $trackIds);
With this:
$postData = array_map("suckySc", $trackIds);
And add this function to the top of the file, before the class opening:
function suckySc ($track){
return 'playlist[tracks][][id]=' . $track;
}