Tobiasz Cudnik

Rails’ ActiveSupport ported to PHP

In The Net on 05.10.2008 at 17:16

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.

  1. 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?

  2. 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.

  3. 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.

All comments are screened for appropriateness. Commenting is a privilege, not a right. Good comments will be cherished, bad comments will be deleted.