| ▲ | johannes1234321 2 hours ago | |
No, the OOP style isn't better. The set of functions one can use in OOP is closed. Imagine I want to AfD a custom string function for a feature which uPpErCaSeS every second letter as I need that for some purpose: I can't do in OOP style. In OOP I could extend the string class, but most other parts of the code won't magically use my string type now. Thus I have to create a free standing function for this (which probably also is better as I don't need internal state of thee object, thus livingnoutisde is good for encapsulation) And thus my string function works different from other string functions.
(The example of course is non sensical and could be reordered, but we argue syntax)Having them all be simple functions makes it equal. Of course there are alternative approaches. C++ argues for years about "uniform call syntax" which would always allow "object style" function calls, which could also find non-memwbr functions where the first argument is of compatible type, but such a thing requires stricter (or even static) typing, this won't work in PHP. | ||