Passing a local property/variable into a function/method within that class?

I'm new to OOP, so this could be an extremely naive question; but whenever I attempt to pass a class local variable into a function within that class using the $this->var syntax, it flags up a syntax error in my IDE (NetBeans).

I've tried encasing it in parentheses (both {$this->var} and $this->{var}) but neither seem to work.

Here's my code:

class password_class {
    public $stretch = 1;
    public $salt = 'DEFINE_SALT';
    public $algo = 'sha256';

    function create_salt() {
        $this->salt = md5(rand()).uniqid();

    function hash_pass($pass, $this->algo, $this->salt, $this->stretch) {


I don't actually plan on using this for password security measures; it was more of a test to see the use of class variables/functions (this will be my first time creating and calling my own class).

Any help would be greatly appreciated!


In OOP if you use instance attribute, you don't need to pass them as params. Infact, if you want to use $this->algo and so on you can simply do:

function hash_pass($pass) {
   // example statement
   $var = hash($this->algo, $this->salt . $pass);

Moreover if you need the params you can do this:

function hash_pass($pass, $algo = null, $salt = null, $stretch = null) {
   if ($salt === null)
      $salt = $this->salt;

   // other if like this
   // example statement
   $var = hash($algo, $salt . $pass);

Need Your Help

NSPredicate for matching property

objective-c core-data nspredicate nsfetchrequest

What in the world am I doing wrong here? Frustrated beyond belief.

Getting rid of GWT MVP boilerplate

java gwt mvp gwt-mvp gwt-places

Following the documentation on places & activities + MVP, for each page I have to create:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.