Do you know of any project that has redefined the native types of PHP (string, array, ints, floats, bools, etc.) as objects? I’m not sure how feasible it would be but i was just thinking that it would be nice to have the native types as objects.
example:
$Name = new String('Mary had a little lamb.');
print($Name->Length); //prints 23
print($Name->Replace('/lamb/', 'duck')); // prints Mary had a little duck.
Would this add to much overhead? Have any thoughts on this?
There are many, many, many (even native) projects that are aiming at that – thing is: Nobody uses them.
There are basically two problems:
+operator. So to sum two number you would need to write$number->add($number2), which isn’t quite intuitive.$number = new Number(function_returning_number());. This also applies to 3rd party libraries.For the first issue there is a PECL extension. It is not bundled with PHP though and is not enabled on normal PHP installations. So you can’t use it for portable applications.
To solve the second issue, there is an Autoboxing RFC. Maybe it will be implemented, maybe not.