Em Tue, 17 Jul 2012 01:27:10 +0200, Andrew Faulds <ajf...@googlemail.com> escreveu:

Through its history, PHP has slowly become more object-oriented. PHP
today has classes, interfaces, objects, namespaces, and so on.
However, much of the language's core functionality is entirely
procedural, composed of functions and constants, much of which are
badly organised and inconsistently named.

I think PHP could benefit from making arrays, strings, integers,
floats, and possibly booleans, into "pseudo-objects". By this I mean
that they are not really objects (they are still primitive types and
keep their passing semantics), but they have methods. For instance,
instead of array_keys($array), one could do $array->keys();

Adding this would make PHP feel more modern and allow people to
embrace more object-oriented programming styles. As a bonus, it would
also give a chance to make the string/array/etc functions better and
more consistently named and possibly implemented.


As I said in IRC, I have some reservations about this.

Let's ignore empty arguments like "make[s] PHP feel modern". That aside, the main argument advanced in this message makes no sense. Adding method call syntax to arrays hardly makes PHP more object oriented. Syntax is unimportant. There's no substantial difference between array_slice($arr, ...) and $arr->slice(...). Object orientation is about polymorphism, encapsulation, inheritance, etc. None of that is advanced by the proposed change. And even if it was, you would still have to justify why that would be a positive development.

Plus, it's very odd to claim this would make PHP more object oriented when there are no objects involved! I don't think it's necessary to enumerate all the differences between objects and arrays -- one that would be particularly confusing would be the different passing semantics (or more accurately, different levels of indirection).

There is, in my opinion, *one* merit here -- redesigning -- and perhaps reimplementing -- the arrays functions API. This will require a lot of work, thought, and time tough.

--
Gustavo Lopes

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to