Object-Oriented PHP
Posted: Thu Nov 12, 2009 2:30 am
Hello!
We want to present you new library's preview, which is used to work with PHP's primitives (such as: string, integer, float and array) in object-oriented way.
Though we've always loved PHP, we had never understood its rough language design.
On the one side developers of PHP forgets about backward compatibility, on other — they don't even try to introduce any coding standards.
Objectives of this library is not in demonstrating of neither authors' nor PHP's skills and possibilities, but in full-fledged usage in development of production projects. Of course, with all benefits given by such approach - "real" type hinting, classes inheritance, etc.
Also, one of the objectives was the replacement for strange and alogical function names (for example, array_flip, but sort — or implode and str_replace. There is a hundreds of examples, actually).
And so, here is the example of library usage:
You can find more detailed description, examples, and, of course, the library itself here.
We're waiting for your criticism with impatience
Sincerely yours,
OOPHP maintainers.
We want to present you new library's preview, which is used to work with PHP's primitives (such as: string, integer, float and array) in object-oriented way.
Though we've always loved PHP, we had never understood its rough language design.
On the one side developers of PHP forgets about backward compatibility, on other — they don't even try to introduce any coding standards.
Objectives of this library is not in demonstrating of neither authors' nor PHP's skills and possibilities, but in full-fledged usage in development of production projects. Of course, with all benefits given by such approach - "real" type hinting, classes inheritance, etc.
Also, one of the objectives was the replacement for strange and alogical function names (for example, array_flip, but sort — or implode and str_replace. There is a hundreds of examples, actually).
And so, here is the example of library usage:
Code: Select all
<?
$map
->clear(function ($key, $val) {
// Delete all elements, where key equals value
return !$key->equals($val);
})
->join(' ') // String
->replace('.', 'dot')
->pregReplace('/([0-9]+)/', function ($m) {
return "!$m[]!"; // Some string with number(e.g. !12345!), is here
})
->changeCase(Str::TITLE, Str::UP_FORCED)
->insert('[inserted]', 5)
->length() // Number
->multiply(4)
->add(6, 9, new Number(15))
->divided(5)
->sum(Number::EVEN)
->dump() // (Number) 1062.51
->root(4)
->round(3) // Just 3 symbols after dot
->dump() // (Number) 5.709
->round(Number::UP) // round to up (ceil)
->hex('15abbf')
->toString() // String ('1420223')
->hash() // 'md5' as default
->dump(); // (String) '0d1b1558224c8f3b125cd905c378c9f7'
We're waiting for your criticism with impatience
Sincerely yours,
OOPHP maintainers.