Pseudo-objects (methods on arrays, strings, etc.)

From: Date: Mon, 16 Jul 2012 23:27:10 +0000
Subject: Pseudo-objects (methods on arrays, strings, etc.)
Groups: php.internals 
Request: Send a blank email to internals+get-61325@lists.php.net to get a copy of this message
Hi there, 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. I am working on an implementation of this for arrays, but I haven't got very far. However, for someone that knows the Zend engine internals, it does not appear to me that adding such things would be very difficult. Thoughts? -- Andrew Faulds (AJF) http://ajf.me/

« previous php.internals (#61325) next »