laravel/framework — pull request #1829 by phpmycoder (2013-07-07 15:42:01+00:00)
Title: View data accessors return by reference

Currently, if you add an array as view data, you cannot append to it through the usual `$arr[] = 123;`. The following:

$view = View::make('some.view')->with('links', array());
$view->links[] = 'http://www.laravel.com';
print_r($view->links);

Raises an error introduced in PHP 5.2 (And still present in 5.4):

Indirect modification of overloaded property Illuminate\View\View::$links has no effect

This is addressed in [PHP bug #39449](https://bugs.php.net/bug.php?id=39449) and was fixed AFAIK in 5.2.6. The bug discusses that when returning by reference from `__get()` (and in Laravel's case `offsetGet()` as well), the above code will output the expected:

Array
(
[0] => http://www.laravel.com
)

Since Laravel requires PHP >= 5.3.0 in `laravel/framework`'s `composer.json`, it should be safe to have `View::__get()` and `View::offsetGet()` return by reference and assume the above will work properly. I added an extra test to the suite to verify this.

Otherwise, the alternative is using an unnecessary `ArrayObject` in place of an array (which I find less graceful than `$view->links[]`).