php.net |  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
Votes:1
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
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-09-19 04:02 UTC] worldoffame at hotmail dot com
Description:
------------
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.  


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-19 04:59 UTC] requinix@php.net
-Status: Open +Status: Wont fix
 [2013-09-19 04:59 UTC] requinix@php.net
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.

http://www.php.net/mailing-lists.php#internals

You may also be interested in the autoboxing RFC.

https://wiki.php.net/rfc/autoboxing
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Oct 20 16:03:42 2021 UTC