Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 Function name must be a string bug

Tags:

php

laravel-5

I get fatal error:

Function name must be a string

When try to return $redirect()->to(blah blah blah...

    if($act=="ban"){
        $ban_until = $request->input('ban_until');
        if(Ragnarok::temporarilyBan($account_id,$banned_by,$ban_until,$ban_reason)){
            return $redirect()->to('banlist');
        }else{
            return $redirect()->to('banlist')->withErrors('Failed to ban, database error');
        }
    }else if($act=="unban"){
        if(Ragnarok::unBan($account_id,$banned_by,$ban_reason)){
            return $redirect()->to('banlist');
        }else{
            return $redirect()->to('banlist')->withErrors('Failed to unban, database error');
        }
    }

Anybody face this bug?

like image 348
Larry Mckuydee Avatar asked Feb 09 '23 21:02

Larry Mckuydee


1 Answers

Try removing the $ from the function as so:

redirect()->to('banlist');

PHP functions must begin with a letter or underscore, you have mistakenly added a $ to the function.

From the PHP Docs:

Function names follow the same rules as other labels in PHP. A valid function name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*.

http://php.net/manual/en/functions.user-defined.php

like image 141
haakym Avatar answered Feb 12 '23 12:02

haakym