Code Igniter REST_Controller.php get parse error [duplicate] - php

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 4 years ago.
I use codeigniter-restserver but i got error like
Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in xxxxxxxxxxxxx\application\libraries\REST_Controller.php on line 835
here the line
if (method_exists(Format::class, 'to_' . $this->response->format))
{
// Set the format header
$this->output->set_content_type($this->_supported_formats[$this->response->format], strtolower($this->config->item('charset')));
$output = Format::factory($data)->{'to_' . $this->response->format}();
// An array must be parsed as a string, so as not to cause an array to string error
// Json is the most appropriate form for such a data type
if ($this->response->format === 'array')
{
$output = Format::factory($output)->{'to_json'}();
}
}
else
{
// If an array or object, then parse as a json, so as to be a 'string'
if (is_array($data) || is_object($data))
{
$data = Format::factory($data)->{'to_json'}();
}
// Format is not supported, so output the raw data as a string
$output = $data;
}

Update your PHP to the leatest version.

Related

multidimensional arrays in php with parse error [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
<?php
array $food= array('healthy'=>
array('Salad','Vege',Pasta'),
'unhealthy'=>
array('pizza','icecream'));
echo $food['unhealthy'][1];
?>
i am writing this code but getting this error on browser:
error : Parse error: syntax error, unexpected '$food' (T_VARIABLE),
expecting '(' in C:\xampp\htdocs\foreach.php on line 2
Remove array at the starting and also there is missing single quote before Pasta.
Try this
<?php
$food = array(
'healthy'=> array('Salad', 'Vege', 'Pasta'),
'unhealthy'=> array('pizza', 'icecream')
);
echo $food['unhealthy'][1];
?>

Parse error: unexpected end of the file, can't find it [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
i'm trying to fix a error, i maked a little search and they send that was something because { or } not closed propely, but i can't find it.
The code is this one:
Parse error: syntax error, unexpected end of file in /movies.php on line 176
the code https://gist.github.com/anonymous/258531c7a81517c47de5
Line 167, close your else statement
<?php $active = get_option('widget_single'); if ($active == "true") { dynamic_sidebar( 'Single Movie' ); } else { ?>
<?php $activar_ads = get_option('activar-anuncio-300-250'); } if ($activar_ads == "true") ?>

How would I get a php uploader to upload to a specific username's directory? [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I may be doing something horribly wrong, so that's why I want to ask this question.
{
$pic = channelart.png;
$pic_loc = $_FILES['pic']['tmp_name'];
mkdir($userRow['user'], 0777, true);
$folder="/.$userRow['user']";
if(move_uploaded_file($pic_loc,$folder.$pic))
{
?><script>alert('Successfully updated channel art.');</script><?php
}
else
{
?><script>alert('Failed to update channel banner.');</script><?php
}
}
I got this error:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /home/video10p/public_html/labs/au/index.php on line 7
Create folder before upload image :-
mkdir($userRow['user'], 0777, true);
Your code like this :-
{
$pic = 'channelart.png';
$pic_loc = $_FILES['pic']['tmp_name'];
mkdir(trim($userRow['user']), 0777, true);
$folder="/.trim($userRow['user'])";
if(move_uploaded_file($pic_loc,$folder.$pic))
{
?><script>alert('Successfully updated channel art.');</script><?php
}
else
{
?><script>alert('Failed to update channel banner.');</script><?php
}
}
Change this $pic = channelart.png; to this $pic = "channelart.png";
You are getting the error because PHP is expecting a String, Variable or statement. The T_ENCAPSED_AND_WHITESPACE token picked up on this line tells us that the parser came upon another assignment, when it was expecting a String, Variable or Numeric.
PHP Tokens are extremely useful to debugging and I would strongly advise taking a look at the page linked above.
This should solve your posted error above.

Parse error when trying to access constant of subobject, [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
I've discovered a very strange behavior of PHP. This code:
class Foo
{
const CONSTANT = 'SomeValue';
}
class Bar
{
public $tmp;
function __construct()
{
$this->tmp = new Foo;
}
}
$object = new Bar;
echo $object->tmp::CONSTANT;
Gives a parse error:
Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM), expecting ',' or ';' in E:\OpenServer\domains\mvc.local\test.php on line 18
What a hell is that? Why it works only if I introduce an intermediate variable:
$interm = $object->tmp;
echo $interm::CONSTANT
I really don't need any additional variables.
PHP 5.6.3
You can access the class constant via the class name, not the object.
e.g. echo Foo::CONSTANT;

PHP 'If' not working [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
Basically I am trying to check if a variable is equal to 5, and then echo something if it is, but I get this error.
PHP Code
if ($adminlevel) === '5' {
echo 'user is owner';
}
Error
Parse error: syntax error, unexpected '===' (T_IS_IDENTICAL) in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\Portfolio -- Website\forum\index.php on line 12
if ($adminlevel === '5') {
echo 'user is owner';
}
Move the paren to include the entire statement.

Categories