It’s year old but found it today on benlog.org. I’m verry happy since i’ve been working on project providing similar chains and now i can use well-thought Rails equivalent. Yet i will still write my own implementation as it differs in many ways.
require_once('ActiveSupport.php');
// Outputs "14th"
_(14)->ordinalize();
// Returns number of bytes in 7.3 megabytes
_(7.3)->megabytes();
// Returns true
_("an example sentence")->endsWith("sentence");
I really liked the idea of ‘_‘ suffix to change returned type. See lots of great examples in Rails Rubyisms Advent.
A Problem I see is that _() functions are often used in the translation context of GNU Gettext.
I bet there is a kind of “namespacing” the function name, isn’t it?
Unfortunately there is no namespacing and you’re right, _() creates many conflicts. Used it myself once and had to change it.
Same has to be done here, although originally author used this particular name.
Admittedly, this technique has a lot of problems – it was pretty much just a proof of concept. Maybe namespaces in 5.3 will change things.