有没有人试图让PHP的系统功能更加面向对象?

时间:2022-11-02 08:21:48

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.

我只是好奇是否有任何项目试图将所有(或大多数)PHP的内置函数分组到更面向对象的类层次结构中。例如,将所有字符串函数分组到单个String类等中。

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.

我意识到这实际上不会解决任何问题(除非修改发生在PHP源代码级别),因为所有内置函数仍然可以在全局命名空间中访问,但它肯定会使可用性更容易。

4 个解决方案

#1


4  

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.

要回答你的问题,是的,有几个库正是你所说的。至于你想要使用的是一个完全不同的问题。 PHPClasses和pear.org是开始寻找这些库的好地方。

Update: As the others have suggested SPL is a good library and wraps many of built in php functions. However there still are lots of php functions that it does not wrap. Leaving us still without a silver bullet.

更新:正如其他人所说的那样,SPL是一个很好的库并且包含许多内置的php函数。但是仍然有很多PHP函数没有包装。离开我们仍然没有银弹。

In using frameworks such as Cakephp and Zend (others too), I have noticed that they attempt to solve some of these problems by including their own libraries and building basics such as DB connectivity into the frame work. So frameworks may be another solution

在使用像Cakephp和Zend(其他人)这样的框架时,我注意到他们试图通过包含自己的库并将诸如DB连接之类的基础构建到框架工作中来解决其中的一些问题。所以框架可能是另一种解决方案

#2


6  

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

方式太多次了。一旦有人发现PHP具有OO功能,他们就会想要将所有内容包装在类中。

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.

PHP中OO的重点在于您可以以任何方式构建解决方案。但是将现有函数包装在Objects中并不会产生太大的回报。

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

据说PHP的核心已经非常面向对象了。看看SPL。

#3


5  

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 5.3 has 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.

我认为像这样的东西是PHP向前推进的整体。作为一名.Net程序员,我发现PHP使用它的100万个和1个全局函数很痛苦。 PHP 5.3具有名称空间是很好的,但是当它们自己的库甚至不是面向对象时更不用说,更不用说使用命名空间了。我不介意PHP作为一种语言,但他们的API非常混乱,可能需要彻底改革。有点像VB成为VB.Net时经历的那种。

#4


4  

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?

我不同意。面向对象编程本质上不比过程编程好。我相信你不应该使用OO,除非你需要多态行为(继承,重写方法等)。使用对象作为代码的简单容器是不值得的开销。对于字符串尤其如此,因为它们使用了很多(例如作为数组键)。每个应用程序通常都可以从某些多态特性中受益,但通常是高级别的。你想要扩展一个String类吗?

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

此外,需要一点历史来理解PHP的奇怪函数命名。 PHP基于标准C库和POSIX标准,并使用许多相同的函数名称(strstr,getcwd,ldap_open等)。这实际上是一件好事,因为它最大限度地减少了语言绑定代码的数量,确保了一套完整的经过深思熟虑的功能(几乎可以在C中用PHP完成的任何事情),并且这些系统库得到了高度优化(例如: strchr通常是内联的,使其速度提高约10倍)。

#1


4  

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.

要回答你的问题,是的,有几个库正是你所说的。至于你想要使用的是一个完全不同的问题。 PHPClasses和pear.org是开始寻找这些库的好地方。

Update: As the others have suggested SPL is a good library and wraps many of built in php functions. However there still are lots of php functions that it does not wrap. Leaving us still without a silver bullet.

更新:正如其他人所说的那样,SPL是一个很好的库并且包含许多内置的php函数。但是仍然有很多PHP函数没有包装。离开我们仍然没有银弹。

In using frameworks such as Cakephp and Zend (others too), I have noticed that they attempt to solve some of these problems by including their own libraries and building basics such as DB connectivity into the frame work. So frameworks may be another solution

在使用像Cakephp和Zend(其他人)这样的框架时,我注意到他们试图通过包含自己的库并将诸如DB连接之类的基础构建到框架工作中来解决其中的一些问题。所以框架可能是另一种解决方案

#2


6  

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

方式太多次了。一旦有人发现PHP具有OO功能,他们就会想要将所有内容包装在类中。

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.

PHP中OO的重点在于您可以以任何方式构建解决方案。但是将现有函数包装在Objects中并不会产生太大的回报。

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

据说PHP的核心已经非常面向对象了。看看SPL。

#3


5  

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 5.3 has 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.

我认为像这样的东西是PHP向前推进的整体。作为一名.Net程序员,我发现PHP使用它的100万个和1个全局函数很痛苦。 PHP 5.3具有名称空间是很好的,但是当它们自己的库甚至不是面向对象时更不用说,更不用说使用命名空间了。我不介意PHP作为一种语言,但他们的API非常混乱,可能需要彻底改革。有点像VB成为VB.Net时经历的那种。

#4


4  

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?

我不同意。面向对象编程本质上不比过程编程好。我相信你不应该使用OO,除非你需要多态行为(继承,重写方法等)。使用对象作为代码的简单容器是不值得的开销。对于字符串尤其如此,因为它们使用了很多(例如作为数组键)。每个应用程序通常都可以从某些多态特性中受益,但通常是高级别的。你想要扩展一个String类吗?

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

此外,需要一点历史来理解PHP的奇怪函数命名。 PHP基于标准C库和POSIX标准,并使用许多相同的函数名称(strstr,getcwd,ldap_open等)。这实际上是一件好事,因为它最大限度地减少了语言绑定代码的数量,确保了一套完整的经过深思熟虑的功能(几乎可以在C中用PHP完成的任何事情),并且这些系统库得到了高度优化(例如: strchr通常是内联的,使其速度提高约10倍)。