title: What is "with" used for in PHP?
body: <p>I have come across this line in the eloquent ORM library:</p>
  
  <pre><code>return with(new static)-&gt;newQuery();
  </code></pre>
  
  <p>I've never seen "with" used before, and cannot find it in the PHP documentation. I'm guessing "with" is a stop-word in most searches, so I am not even getting close.</p>
  
  <p>Never having encountered "with" in many years of programming PHP, I feel like I'm missing out. What does it do? I did come across one passing comment regarding the ORM, that mentioned "with" is no longer needed in PHP-5.4, but that was as much as was said. If that is accurate, it would be good to know what the PHP-5.4 equivalent is.</p>
  
  <p>Update: Details supporting the answer:-</p>
  
  <p>I found this helper function in Laravel's Immuminate/Support/helpers.php helper script:</p>
  
  <pre><code>if ( ! function_exists('with'))
  {
      /**
       * Return the given object. Useful for chaining.
       *
       * @param  mixed  $object
       * @return mixed
       */
      function with($object)
      {
          return $object;
      }
  }
  </code></pre>
  
  <p>as mentioned in a few of the answers. That global-scope function allows an object to be created and methods run in t, in one statement. It is (somehow) registered in the composer autoload_files.php script when Laravel is installed, so it gets loaded on every page, even though it contains no classes.</p>
  
  <p>Thanks all. It pays not to assume that everything <em>must be</em> a namespaced class in modern frameworks.</p>