Welcome Guest, Not a member yet? Register   Sign In
Does the error "should not be called statically" mean my namespace or use is wrong?
#1

(This post was last modified: 01-23-2022, 08:31 AM by castle.)

Hi,
I'm confused here. How do I call a method into a controller from another Controller?
PHP Code:
<?php
/**
 * In strict mode, only a variable of exact type of the “type declaration”
 * will be accepted, or a TypeError will be thrown.
 */
declare(strict_types=1);

namespace 
App\Controllers\Backend;

use 
App\Controllers\BaseController;
use 
App\Controllers\Backend\Authentication\Staff;
//use App\Libraries\Auth;


/**
 * The backend starts here.
 */
class Bootstrap extends BaseController
{

 
/**
 * Let's get it started. But first, who are you?
 */
 
public function index()
 {
 

 
// if ( ! $this->authentication->logged('staff'))
 // { 
 
Staff::login();
 
// }
 // else
 // {
 // $this->dashboard();
 // }
 
}

I thought that once I declare the line
Code:
use App\Controllers\Backend\Authentication\Staff;
I should be able to call any method from that class with
Code:
Staff::method_name();
However, that doesn't work and I'm getting the error:
Code:
Non-static method App\Controllers\Backend\Authentication\Staff::login() should not be called statically
What am I missing?
Thanks
Reply
#2

>  Does the error "should not be called statically" mean my namespace or use is wrong?

No.
You need to know the difference between static calls and non static calls.
https://www.php.net/manual/en/language.oop5.basic.php
Reply
#3

(This post was last modified: 01-23-2022, 11:05 PM by manager.)

Quote:What am I missing?

You are calling non-static method like static. 
Can you show your Staff class?
Reply
#4

Look here if you use Laravel : Facades
Reply




Theme © iAndrew 2016 - Forum software by © MyBB