Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

parse error, expecting `T_PAAMAYIM_NEKUDOTAYIM' error in activecollab model class

I'm working on activecollab custom module's permissions, and getting this error message when try to calling function of static method dont know why; please do help will be really appericiatable ..

Parse error: parse error, expecting `T_PAAMAYIM_NEKUDOTAYIM' in D:\wamp\www\activecollab\public\activecollab\3.0.9\modules\projectcomrequest\models\Projectcomrequests.class.php on line 130

the code I did in model file is:

  class Projectrequests extends DataManager {

   ...
   ....

        function getPermissionValue($name){
            $roles = Roles::find();
            foreach($roles as $role) {
                if($role->getPermissionValue($name))
                    return true;
                else
                    return false;
        }

        static function canAccess() {
          if(self::getPermissionValue('can_use_project_request')) return true;
            return false;
        } // canAccess

  ...
  ..

  }

calling in controller by this:

echo Projectrequests::canAccess();
like image 595
Shadman Avatar asked Dec 28 '22 00:12

Shadman


2 Answers

    foreach($roles as $role) {
        if($role->getPermissionValue($name))
            return true;
        else
            return false;

You're missing a closing } there. So it should be:

  class Projectrequests extends DataManager {

   ...
   ....

        function getPermissionValue($name){
            $roles = Roles::find();
            foreach($roles as $role) {
                if($role->getPermissionValue($name))
                    return true;
                else
                    return false;
            } // <-- here
        }

        static function canAccess() {
          if(self::getPermissionValue('can_use_project_request')) return true;
            return false;
        } // canAccess

  ...
  ..

  }
like image 189
psx Avatar answered Dec 31 '22 15:12

psx


A static method doesn't have a class context $this as you try to call in the first line of canAccess(). You should call self:: instead of $this-> to access the class context and then you can only call other static field and methods. You will have to make getPermissionValue also static.

A few more errors:

  • You forgot a { in your foreach. Fixed this for you (only return true inside the loop, the else construction is useless because otherwise your foreach only loops once).
  • You can immediately return the value of the call to getPermissionValue in canAccess since it is a boolean anyway (the if-else construction is kind of useless).

Corrected code:

static function getPermissionValue($name){
    $roles = Roles::find();
    foreach($roles as $role) {
        if($role->getPermissionValue($name))
            return true;
    }    
    return false;
}

static function canAccess() {
    return self::getPermissionValue('can_use_project_request');
} // canAccess

I would like to advice as well to use access modifiers like public and private as it is good practice.

like image 44
Styxxy Avatar answered Dec 31 '22 14:12

Styxxy