dscss8996
2013-11-20 18:28 阅读 23
已采纳

PHP类变量公开给出错误

I'm really new to php classes and now i have an error on my code. I have read some PHP documentations about classes and stuff, but something isn't just working correctly now.

Here's the code

public function change_salts($user_id) {
        global $mysqli_db;
        public $new_salt_one = "LOL"; //SaltyLogin::makesalt(60);
        private $new_salt_two = SaltyLogin::makesalt(60);
        mysqli_query($mysqli_db, "UPDATE `".SaltyLogin::sanitize(SALTY_MYSQLI_TB_SALTS)."` SET `".SaltyLogin::sanitize(SALTY_MYSQLI_TB_SALTS_SALT_ONE)."`='".$new_salt_one."' WHERE `".SaltyLogin::sanitize(SALTY_MYSQLI_TB_USER_ID)."` = '".SaltyLogin::sanitize($user_id)."'");
        mysqli_query($mysqli_db, "UPDATE `".SaltyLogin::sanitize(SALTY_MYSQLI_TB_SALTS)."` SET `".SaltyLogin::sanitize(SALTY_MYSQLI_TB_SALTS_SALT_TWO)."`='".$new_salt_two."' WHERE `".SaltyLogin::sanitize(SALTY_MYSQLI_TB_USER_ID)."` = '".SaltyLogin::sanitize($user_id)."'");
    }

Now this is the error I get all the time.

Parse error: syntax error, unexpected 'public' (T_PUBLIC) in C:\xampp\htdocs\GitHub\Salty-login\functions.php on line 60

For full source code, have a look at github and naturally branch wip-2.

Thanks in advance.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    duanchun1881 duanchun1881 2013-11-20 18:30

    You can't declare class variables in side of a function. You have to either move them out of the method or make them local to the function only:

    Option 1

    public $new_salt_one = "LOL"; 
    private $new_salt_two = '';
    public function change_salts($user_id) {
        global $mysqli_db;
        $this->new_salt_two = SaltyLogin::makesalt(60);
        mysqli_query($mysqli_db, "UPDATE `".SaltyLogin::sanitize(SALTY_MYSQLI_TB_SALTS)."` SET `".SaltyLogin::sanitize(SALTY_MYSQLI_TB_SALTS_SALT_ONE)."`='".$this->new_salt_one."' WHERE `".SaltyLogin::sanitize(SALTY_MYSQLI_TB_USER_ID)."` = '".SaltyLogin::sanitize($user_id)."'");
        mysqli_query($mysqli_db, "UPDATE `".SaltyLogin::sanitize(SALTY_MYSQLI_TB_SALTS)."` SET `".SaltyLogin::sanitize(SALTY_MYSQLI_TB_SALTS_SALT_TWO)."`='".$this->new_salt_two."' WHERE `".SaltyLogin::sanitize(SALTY_MYSQLI_TB_USER_ID)."` = '".SaltyLogin::sanitize($user_id)."'");
    }
    

    Option 2

    $new_salt_one = "LOL"; 
    $new_salt_two = SaltyLogin::makesalt(60);
    
    点赞 评论 复制链接分享

相关推荐