Table of Contents

PHP RFC: Collections

Introduction

This RFC suggests to introduce a new

Definitions

Term Description
Biscuits Better than cookies

Proposal

Basics

Design Goals:

Non Design Goals:

Syntax

collection Articles(int => Article)
{
}

Is short hand for, but acts like ArrayAccess too:

class Articles
{
	private array $__collection_items;

	public function __construct()
	{
		$this->__collection_items = [];
	}

	public function offsetExists(int $offset): bool
	{
		return array_key_exists($offset, $this->__collection_items);
	}

	public function offsetGet(int $offset) : ?Article
	{
		return $this->offsetExists($offset) ? $this->__collection_items[$offset] : NULL;
	}

	public function offsetSet(int $offset, Article $item) : void
	{
		$this->__collection_items[$offset] = $item;
	}

	public function offsetUnset(int $offset): void
	{
		unset($this->__collection_items[$offset]);
	}
}

Implementation Details

Backward Incompatible Changes

Proposed PHP Version(s)

Next PHP 8.x

RFC Impact

There will be no impact to SAPIs, existing extensions, nor Opcache.

Open Issues

Questions and Answers

Why is this not a composer package?

Future Scope

Proposed Voting Choices

Either “yes” or “no” on including the proposed class.

Patches and Tests

There is no patch yet.

Implementation

After the project is implemented, this section should contain

  1. the version(s) it was merged into
  2. a link to the git commit(s)
  3. a link to the PHP manual entry for the feature
  4. a link to the language specification section (if any)

References

Rejected Features

Nothing rejected yet.

Changes

0.1.0 — 2023-04-24