There are many, many (even native) projects that are aimed at this: the fact is that no one uses them.
There are basically two problems:
- PHP has only limited operator overloading. You cannot overload the
+ operator. So, to sum two numbers, you need to write $number->add($number2) , which is not very intuitive. - PHP has many predefined functions. It can be argued that PHP has the most powerful standard library of all programming languages. But: all of these functions return native types, not boxed ones. So you need to write something like
$number = new Number(function_returning_number()); . This also applies to third-party libraries.
There is a PECL extension for the first release. It is not PHP related, although it is not included in regular PHP installations. Therefore, you cannot use it for portable applications.
To solve the second problem, there is Autoboxing RFC . Perhaps this will be realized, perhaps not.
NikiC source share