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.
Related
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.
I'm getting this error of :
Parse error: syntax error, unexpected T_PUBLIC, expecting T_CLASS in C:\xampp\htdocs\app\class.engine.php on line 75
I don't know what the problem is i've tried everything really but still nothing
Codes around Line 75
final public function disconnect()
{
global $core;
if($this->connected)
{
if($this->mysql['close'])
{
$this->connected = false;
}
else
{
$core->systemError('MySQL Engine', 'MySQL could not disconnect.');
}
}
}
Any help? :)
Does this function appear inside the rest of your class definition {} ? Sounds like maybe your class { ... } closes prematurely before this.
Turns out you were declaring a new function within a function, because of one missing closing bracket.
See here: http://www.pastebin.com/iwSXr1Qa the error was at line 55
I saw this SO already, tried to manipulate, but failed.
I received the error of:
Parse error: syntax error, unexpected '$userN' (T_VARIABLE) in ...
I tried var_dump, printf, echo and none of them work.
code:
class User {
private $dbh;
public function __construct($host,$user,$pass,$db) { ...}
public function getQs(){ ...}
}
$userN=new User(...);
var_dump $userN;
NOTE: the ... are there to hide sensitive information, they are actual code/variable that is valid in place.
Please help. Thanks
var_dump $userN; should be var_dump($userN);
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