Could someone help me find the error? [closed]

1

When I want to run my code I get this error:

  

Use of undefined constant - assumed ''

<?php
namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;

class UserController extends Controller
{
    public function postSignUp(Request $request)
   {
        $email=$request['email'];
        $first_name=$request['first_name'];
        $password=bcrypt($request['password']);

        $user = new User();
        $user->email = $email;
        $user->first_name = $first_name;
        $user->password = $password;

        $user->save();

        return redirect()->back();
    }
    public function postSignIn(Request $request)
    {

    }
 }
?>
    
asked by Mike3911 30.05.2017 в 11:01
source

1 answer

3

You have a problem with BOM little endian UTF-16 that you have moved to the end of the script.

This causes a syntax error after the closing of the last bracket (a fe ff character corresponding to the displaced BOM) that tries to interpret as constant and converts to a string.

Removing the character solves the problem. If your editor does not show non-visible characters, you can delete the entire line (selecting from the previous line to the later one), rewriting it again later.

Here is the corrected code for you to copy and paste back to an empty file:

<?php
namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;

class UserController extends Controller
{
    public function postSignUp(Request $request)
   {
        $email=$request['email'];
        $first_name=$request['first_name'];
        $password=bcrypt($request['password']);

        $user = new User();
        $user->email = $email;
        $user->first_name = $first_name;
        $user->password = $password;

        $user->save();

        return redirect()->back();
    }
    public function postSignIn(Request $request)
    {

    }
 }
?>

The problem is that you probably created the document with an editor that generated the BOM at the beginning of the file and then you opened it with a different one and you moved it silently (and apparently invisible) to that place.

    
answered by 30.05.2017 / 11:15
source