title: Is it possible to pass object variable to "use" section in anonymous function
body: <p>So basically I am trying to pass current object variable to my anonymous function like this:</p>
  
  <pre class="lang-php prettyprint-override"><code>$options = Option::whereHas('texts', function($query) use ($this-&gt;language) {
          $query-&gt;where(['language_id' =&gt; $this-&gt;language-&gt;id, ]);
      })-&gt;where(['active' =&gt; 1, ])
      -&gt;get();
  </code></pre>
  
  <p>But it gives:</p>
  
  <blockquote>
    <p>syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ',' or ')'`.</p>
  </blockquote>
  
  <p>Anyway, if I will set another variable to <code>$this-&gt;language</code> and pass it in anonymous function, it will work properly.</p>
  
  <pre class="lang-php prettyprint-override"><code>$language = $this-&gt;language;
  $options = Option::whereHas('texts', function($query) use ($language) {
          $query-&gt;where(['language_id' =&gt; $language-&gt;id, ]);
      })-&gt;where(['active' =&gt; 1, ])
      -&gt;get();
  </code></pre>
  
  <p>So, what is correct way to pass object variable to "use" section in anonymous function?</p>