是否有PHP等效的Objective-C类别?

问题描述:

For the short period of time I subjected myself to Objective-C, I swore a lot, but one thing I thought was fabulous was categories.

I could add a method to the NSString object as a category, and it was available on any NSString object in my application. Something similar is now possible in Delphi and probably many other languages.

Is that possible in PHP?

If so is there a good tutorial, and can I extend the PDO object?

I have searched helpers and categories with little success. I seem to remember reading that it was possible.

在很短的时间内我自己去了Objective-C,我发誓很多,但有一件事我想的 很棒的是类别。 p>

我可以将一个方法添加到NSString对象作为一个类别,它可以在我的应用程序中的任何NSString对象上使用。 现在可以在Delphi和许多其他语言中使用类似的东西了。 p>

在PHP中可以实现吗? p>

如果有,那么有一个很好的教程, 我可以扩展PDO对象吗? p>

我搜索了助手和类别但收效甚微。 我似乎记得读到它是可能的。 p> div>

No it is not possible in PHP to add functionality to existing native classes.

And yes it is indeed possible to extend PDO.

class MyClass extends PDO { /* All your class stuff here */ }