Are these kinds of things possible?

Similar to the Ruby way, I was wondering with the annonymous functions / closures etc.

$books->each = function($book) {

echo $book->name;


Is this kind of thing possible in PHP yet? If so could we see the features going more like this in Yii?

Well, if they are possible with PHP, they are possible with Yii as well. As for your example: No, I don’t think closures work that way.

foreach($books as $item){

    echo $item->name;


array_walk($books, function($book) { echo $book->name; });


$echoName = function(Book $book) { 

    echo $book->name; 


array_walk($books, $echoName);

foreach is the best in this case :)