0

I have a class called class Settings in Settings.php

    class Settings

{  public function UserRole($is_login = false){

        $default = ['id' => 1, 'name' => 'New user'];

        $user_role = $this->getUser($id);
        if( !$user_role )
            return $default;

else ... etc.}
}

The problem is, in my User.php, where I have this:

    use Settings;

class Helper_User extends \Zend_View_Helper_Abstract
{

public function mainNavigation($is_collapsed = false){
        $instance = Zend_Controller_Front::getInstance();
      ...
        return $this->container();
    }

 public function container(){
        $newuser = $this->getNewUser();

        $html = "blabla";
        return $html;
    }
}

and anywhere I try to put this $role = $this->Settings->UserRole();

I have this error

Uncaught Error: Call to a member function UserRole() on null.

Can you please help what is wrong here? Thanks.

brombeer
  • 8,716
  • 5
  • 21
  • 27
Darksymphony
  • 2,155
  • 30
  • 54
  • 1
    Error seems quite clear, `$this->Settings` is null. (Not sure how the second code is related to all this) – brombeer Apr 15 '19 at 09:08
  • 1
    Where did you provide any value for `$this->Settings`? – Nico Haase Apr 15 '19 at 09:09
  • Possible duplicate of [Reference - What does this error mean in PHP?](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – Nico Haase Apr 15 '19 at 09:10

1 Answers1

0

ah ok, I found out that if I call it like this:

    $loggedUser = new Settings($this);
    $role = $loggedUser->UserRole();

then it is working fine. It did not worked if I did it like $this->Settings->UserRole();

Darksymphony
  • 2,155
  • 30
  • 54