1

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
  • You shouldn't use encapsulation inside of the functions/methods, only in class declarations Commented Nov 20, 2013 at 18:30

1 Answer 1

3

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);
Sign up to request clarification or add additional context in comments.

1 Comment

plus class variables can't be initialized with expression results. constants only.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.