|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #65703 Primitives, Strings and Arrays as Objects
Submitted: 2013-09-19 04:02 UTC Modified: 2013-09-19 04:59 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: worldoffame at hotmail dot com Assigned:
Status: Wont fix Package: Class/Object related
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: worldoffame at hotmail dot com
New email:
PHP Version: OS:


 [2013-09-19 04:02 UTC] worldoffame at hotmail dot com
Well currently in PHP not everything is an object, if you use the object operator -> on an integer variable(like 2->toFloat()) you will get an error. Strings and Arrays are not object either, and these are bigger problems than primitives like integers, floats and booleans. 

So I propose that in PHP 5.6 everything is an object. The PHP core will provide special classes such as Boolean, Integer, Float, String and Array, all of them have methods for client users to manipulate. 

For Booleans and Integers, the methods will be quite limited. But for Strings and Arrays, each currently available orphan string/array functions can be made into methods. Below is how you'd play with strings and arrays in PHP 5.5 and 5.6:

PHP 5.5:
echo strtoupper("this is a string");
$array = sort([2, 5, 1, 4, 6, 3]);

PHP 5.6:
echo "this is a string"->toUpper();
$array = [2, 5, 1, 4, 6, 3]->sort();

Id say the proposed methods are much more elegant, and thats how Python and Ruby deal with strings and arrays. Also the keyword array will be removed as Array will be used as a class name.

In PHP 5.7 and beyond it may be a good point to consider deprecating the traditiona/procedural way of creating primitive types, strings and arrays.  


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-19 04:59 UTC]
-Status: Open +Status: Wont fix
 [2013-09-19 04:59 UTC]
This has been brought up numerous times before with the answer of "not going to 
happen anytime soon".

You can bring this subject up on the internals mailing list but know that 
requesting such a huge (I don't know if I can stress that enough) change simply 
because other languages do it that way won't get much of a positive response.

You may also be interested in the autoboxing RFC.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Jan 28 13:05:54 2023 UTC