I’ve been coding with PHP for a while, and I’ve been relatively irritated at the inconsistencies in the procedural functions (especially Strings and Arrays).
With the support for objects, I’ve been wishing that PHP had a native implementation of Arrays and Strings as objects so that I could write code like:
$arr = new Array('foo', 'bar');
$item = $arr->pop();
Making an Array-like object isn’t overly difficult, however, there’s a significant performance hit. All it would end up being is a wrapper for the array constructs anyway.
Are there other core objects that PHP should have for Object Oriented PHP?
EDIT to add:
This is NOT about how you can use arrays as objects; in fact, I specifically do not want the discussion of arrays in the answer, as that’s not what the question is about. I used arrays as an example, and it seems no one read the question. I am interested in other classes/objects that should exist natively in core PHP.
Edit:
It will be possible in PHP 6 with aoutoboxing
is the automatic conversion the compiler makes between the primitive (basic) types and their corresponding object wrapper classes (eg, array and ArrayObject, double and Double, etc).
There would be a special function named __autobox()
For Example :
Example using: