|
|
|
|
|
by birkbork
4349 days ago
|
|
If you want to order your program in a specific way, you introduce the appropriate level of abstraction. Same as with any other language. EDIT: i totally agree that the standard functions are a complete mess in PHP. But they have to stay around for backwards compatibility. Have a look at the SPL classes: http://php.net/manual/en/book.spl-types.php |
|
For example, how would I make a string abstraction? Create a class? Ok, so we have:
$str = new String("foo") $str->replace(...)
over
$str = "foo" str_replace($str, ...)
This is fine, if we ignore the fact it's much slower.
Where it really gets annoying is PHP's lack of operator overloading. That means to concatenate I'd need to do
$str->concat($str2)->concat(new String(" "))->concat($str3)
instead of
$str . $str2 . " " . $str3
There's things you can do to make the API a little bit more convenient (i.e. allow it accept PHP strings, etc.), but ultimately it becomes a huge pain, especially if you want to start interoperating with other libraries that are using a different abstraction or, more likely, using the regular PHP types and functions.