Req #80620 [Nab]: feature request - List data types
| From: | requinix@php.net | Date: | Wed, 13 Jan 2021 23:29:47 +0000 |
| Subject: | Req #80620 [Nab]: feature request - List data types | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-231551@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80620&edit=1
ID: 80620
Updated by: requinix@php.net
Reported by: fazedoutofturn at hotmail dot com
Summary: feature request - List data types
Status: Not a bug
Type: Feature/Change Request
Package: *Programming Data Structures
PHP Version: Next Major Version
Block user comment: N
Private report: N
New Comment:
Sounds like you want SplDoublyLinkedList.
https://www.php.net/manual/en/class.spldoublylinkedlist.php
Queue or Stack could be more appropriate for your use case.
https://www.php.net/manual/en/class.splqueue.php
https://www.php.net/manual/en/class.splstack.php
Previous Comments:
------------------------------------------------------------------------
[2021-01-13 23:07:22] fazedoutofturn at hotmail dot com
@requinix
Well, what I mean is an actual List data type or a List object data type. Reading the link you gave
me, it pertains to just arrays. So basically pluralizing objects. What I am talking about is
something like this as an example (not working for obvious reasons).
------
<?php
class Author {
public function __construct(public string $first_name = '', public string $middle_name =
'', public string $last_name = '') {
}
}
List<Author> $authors = new List<Author>();
$authors->add(new Author('Courtney', '', 'Peppernell'));
$authors->add(new Author('William', '', 'Shakespeare'));
$authors->add(new Author('Claudia', '', 'Rankine'));
$authors->add(new Author('Jacqueline', '', 'Woodson'));
$authors->add(new Author('Edgar', 'Allan', 'Poe'));
// Would give you a list of authors as such
// List <Courtney Peppernell>, <William Shakespeare>, <Claudia Rankine>,
<Jacqueline Woodson>, <Edgar Allan Poe>
print_r($authors);
------
Since PHP has already adopted "some" of Java's OOP, why can't we just adopt
everything? Most languages have List data types so why can't PHP? I know people will say arrays
are enough, but having a consistency in OOP would help people move around languages to languages
more. Plus, it sort of seems PHP is heading that way anyways where everything is more strictly
typed.
------------------------------------------------------------------------
[2021-01-13 06:54:28] requinix@php.net
See the proposal for the "array_is_list" function, and related messages on the internal
mailing list.
https://wiki.php.net/rfc/is_list
------------------------------------------------------------------------
[2021-01-13 05:08:30] fazedoutofturn at hotmail dot com
Description:
------------
This is my first time requesting for a PHP feature or using this report system. But since PHP 8 has
been released, could we get List data types? We already have scalar data type declarations now. It
would be nice to have other data types that other languages has as well. Arrays are nice, but having
Lists would make PHP head towards a more consistent OOP language.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80620&edit=1