Troubleshooting unexpected T_PUBLIC error
Date : March 29 2020, 07:55 AM
wish of those help I get this error... <?PHP
class Session{
private static $instance;
function __construct()
{
session_start();
echo 'Session object created<BR><BR>';
}
public static function getInstance()
{
if (!self::$instance) {
self::$instance = new Session();
}
return self::$instance;
}
}
|
FatalErrorException: Parse: syntax error, unexpected T_PUBLIC in
Date : March 29 2020, 07:55 AM
this will help You have to put the action method inside a controller class. I suggest you start with basic Object-Oriented PHP before diving into Symfony2.
|
syntax error, unexpected 'public' (T_PUBLIC)
Tag : php , By : Valentine
Date : March 29 2020, 07:55 AM
I wish did fix the issue. You need a context of class to use access identifiers. Your code should be: class MyClass {
public function upload() {
// getting all of the post data
$file = array('image' => Input::file('image'));
// setting up rules
$rules = array('image' => 'required',); //mimes:jpeg,bmp,png and for max size max:10000
// doing the validation, passing post data, rules and the messages
$validator = Validator::make($file, $rules);
if ($validator->fails()) {
// send back to the page with the input data and errors
return Redirect::to('upload')->withInput()->withErrors($validator);
}
else {
// checking file is valid.
if (Input::file('image')->isValid()) {
$destinationPath = 'uploads'; // upload path
$extension = Input::file('image')->getClientOriginalExtension(); // getting image extension
$fileName = rand(11111,99999).'.'.$extension; // renameing image
Input::file('image')->move($destinationPath, $fileName); // uploading file to given path
// sending back with message
Session::flash('success', 'Upload successfully');
return Redirect::to('upload');
}
else {
// sending back with error message.
Session::flash('error', 'uploaded file is not valid');
return Redirect::to('upload');
}
}
}
}
|
Parse error: syntax error, unexpected 'public' (T_PUBLIC) in codeifniter
Tag : php , By : PatrickSimonHenk
Date : March 29 2020, 07:55 AM
help you fix your problem this error occurs because you declare $username within a method. You shouldn't. Use this instead, it declares it outside of the method, and inside of the class. <?php
/**
* MY_Controller extends CI_Controller
*/
class MY_Controller extends CI_Controller
{
public $username;
function __construct()
{
parent::__construct();
$slogin = $this->input->cookie('userblog');
if (!empty($slogin))
{
$this->load->library('encrypt');
$login = $this->encrypt->decode($slogin,ENCRYPT_KEY) ;
echo 'login is : ' .$login ;
$login_info = explode('_',$login) ;
$this->username = $login_info[0] ;
$is_login = $login_info[1];
if ( $is_login !='islogin')
{
redirrect('login');
}
}
$login = $this->session->userdata('login') ;
if(!empty($login))
{
if ($login != true)
{
redirect('login');
}
}
else
{
redirect('login');
}
}
}
?>
|
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting end of file
Tag : php , By : Der Ketzer
Date : March 29 2020, 07:55 AM
|