0

In

public function bind($query, $input_param, $btypes)
{
    // $input_param = $this->ref_arr($input_param);  // this self assignment gives an error!
    $input_ref = $this->ref_arr($input_param);       // this works 
}

I learned this by trial and error... but I'm trying to figure out why?

I haven't had a chance to form more test cases but if I use $input_param as in input to the function I can not return the result back to $input_param. Once I change the name to something else, in this case $input_ref it works.

3
  • 4
    It's not very clear what you're asking. Can you try to clean it up a bit? Commented Sep 12, 2011 at 3:43
  • What do you mean by "does not work"? Does it give you an error? And what does ref_arr() look like? Commented Sep 12, 2011 at 4:33
  • Based on code shown here, as far as I can tell both of those should work, so the issue is most likely elsewhere. Commented Sep 12, 2011 at 5:17

2 Answers 2

2

The $this keyword references the current object you are in.

So if you are in code that is in a class like this:

class foo {
   public function __construct() {
      $this->bar = 'that'; // works because $this references the foo object
   }
}

Should work. In the case where you are outside of an object however, $this would not work, because there is no object for $this to reference.

class foo {
   public function __construct() {

   }
}
$this->bar = 'that'; // will not work because you are not inside of any object
Sign up to request clarification or add additional context in comments.

Comments

0

I don't have time to reproduce this...simply changing the variable name fixed the problem.

Comments

Your Answer

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