Categories
Posts

Underscore.php

Underscore.php is a port of the popular Underscore.js to PHP.

Some of these methods look useful, others left me wondering why they were included. For example, __::toArray():

[sourcecode lang=”php”]
$stooge = new StdClass;
$stooge->name = ‘moe’;
$stooge->age = 40;
__::toArray($stooge); // array(‘name’=>’moe’, ‘age’=>40)
[/sourcecode]

When just casting it to an (array) does the same thing. Indeed, that is all the __::toArray() method does internally.

Another example is __::isArray(), when PHP already has an is_array() function.

Perhaps all of that is just an effort to be as compatible as possible with the original Underscore.js. Underscore.php is available under an MIT style license at https://github.com/brianhaveri/Underscore.php. I may just pluck out some of the specific functions that look the most useful and not worry about the rest.

Leave a Reply

Your email address will not be published. Required fields are marked *