tags:

views:

311

answers:

4

I'm just curious if any project exists that attempts to group all (or most) of PHP's built-in functions into a more object-oriented class hierarchy. For example, grouping all the string functions into a single String class, etc.

I realize this won't actually solve any problems (unless the modifications took place at the PHP source code level), since all the built-in functions would still be accessible in the global namespace, but it would certainly make usability much easier.

+6  A: 

I think something like this is intergral for PHP to move forward. Being mainly a .Net programmer, I find PHP painful to work in with it's 1 million and 1 global functions. It's nice that PHP 6 will have namespaces, but it doesn't help things much when their own libraries aren't even object oriented, let alone employ namespaces. I don't mind PHP as a language so much, but their API is terribly disorganized, and it probably needs a complete overhaul. Kind of like what VB went through when it became VB.Net.

Kibbee
Agreed, but... their documentation is unparalleled.
Allain Lalonde
I definitely agree, I'd love to see this as a priority for PHP 6. Since they are now releasing namespace support in the forthcoming 5.3 release, I'm hoping the next logical step is to start moving their standard library functions to its own namespace/class heirarchy.
Wilco
we can only hope
SeanDowney
+6  A: 

Way too many times. As soon as someone discovers that PHP has OO features they want to wrap everything in classes.

The point to the OO stuff in PHP is so that you can architect your solutions in whichever way you want. But wrapping the existing functions in Objects doesn't yield much payoff.

That being said PHP's core is quite object oriented already. Take a look at SPL.

Allain Lalonde
SPL is definitely a step in the right direction. I just think it's extremely messy having so much core functionality in the global namespace. It seems ridiculous to me that I have to worry about naming collisions with what is built-in to the language.
Wilco
If you write your own code in an OO way, there's rarely any worry. Since the chances of conflicting with anything in the core is almost zero. And even if you do, it'll fail. I completely get where you're coming from though.PHP just doesn't have that flavor. Python might be a better choice.
Allain Lalonde
+1  A: 

To Answer your question, Yes there exists several of libraries that do exactly what you are talking about. As far as which one you want to use is an entirely different question. PHPClasses and pear.org are good places to start looking for such libraries.

As for me, i just have everything already memorized and figure i'm set in my ways. Unless there was a new php standard that used these libraries I can't see there being any one silver bullet library.

SeanDowney
+2  A: 

I don't agree. Object Oriented Programming is not inherently better than procedural programming. I believe that you should not use OO unless you need polymorphic behavior (inheritance, overriding methods, etc). Using objects as simple containers for code is not worth the overhead. This is particularly true of strings because their used so much (e.g. as array keys). Every application can usually benifit from some polymorphic features but usually at a high level. Would you ever want to extend a String class?

Also, a little history is necessary to understand PHP's odd function naming. PHP is grounded around The Standard C Library and POSIX standard and uses many of the same function names (strstr, getcwd, ldap_open, etc). This is actually a good thing because it minimizes the amount of language binding code, ensures that a full well thought out set of features (just about anything you can do in C you can do in PHP) and these system libraries are highly optimized (e.g. strchr is usually inlined which makes it about 10x faster).