joomla/joomla-framework — pull request #216 by elkuku (2013-09-12 13:18:23+00:00)
Title: Add a global with() method.

This is about adding a global function.
Uhhh what ? (wtf).... No, please keep on reading ;)

**Benefits**
* Reduce the usage of **local variables**.
* Add **forward compatibility** for the PHP 5.4 feature [Class member access on instantiation](http://php.net/manual/en/migration54.new-features.php).

**Example**:
Plain PHP 5.3:
```php
$class = new Class;
$result = $class->method();
```
Using the proposed `with()` function:
```php
$result = with(new Class)->method();
```
Now when switching the minimum requirements to PHP 5.4 you simply change it to:
```php
$result = (new Class)->method();
```
and remove the whole evil global function from the code base...

I hope, you can see the benefits.

The method will be added to a global file in `src/Joomla/PHP/methods.php` which will be loaded by Composers [files autoload mechanism](http://getcomposer.org/doc/04-schema.md#autoload).

----

**Disclaimer**
This has been stolen from the Laravel framework and I am posting the whole magical function here, hoping that they won't prosecute me for copyright infringement ;)
From [laravel/framework/blob/master/src/Illuminate/Support/helpers.php#L869](https://github.com/laravel/framework/blob/master/src/Illuminate/Support/helpers.php#L944)
```php
function with($object)
{
return $object;
}
```
The power of simplicity :)