Hi Mel,

I love this idea. We should definitely make it official that procedural
style API is unfavourable and should not be added to new classes.
On top of that, I would be in favor of deprecating all existing procedural
APIs.
- It's making it more difficult to maintain code in two variants
- It's making it difficult to maintain documentation
- It's confusing for users
- Procedural API is usually much more verbose than OO style
- The return values often do not match

OO style allows method chaining vs function nesting with procedural. The
only time when I ever saw any advantage to procedural style is when using
date_create(). Depending on what one is used to, procedural style can be
cleaner and more understandable.
echo date_diff(date_create('2000-01-01'),
date_create('2000-01-05'))->format('%R%a days');
vs
echo (new DateTime('2000-01-01'))->diff(new
DateTime('2000-01-05'))->format('%R%a days');

However, above examples are not apples to apples. When using date_create
with variable input, you must employ manual error checking as it won't
throw any errors like OO does. When you factor this in, the first example
becomes a nightmare and a gun to shoot yourself in the foot. It happened to
me.

So, maybe what we could do is slowly deprecate all procedural APIs, but
leave some exceptions as handy shortcut functions. If that's not possible,
then I wouldn't mind seeing all procedural APIs go away.

Regards,
Kamil

Reply via email to