[php-src] Issue #15795: Array of something | They cry "generics" meaning only THIS
| From: | 6562680 | Date: | Sun, 08 Sep 2024 01:59:59 +0000 |
| Subject: | [php-src] Issue #15795: Array of something | They cry "generics" meaning only THIS | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-247719@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/15795
Author: 6562680
### Description
* Of course this proposal may be merged with any other collection suggestions or something
Actually Generics may be used only in two possible ways:
1. Create Concrete (example: repository) that implements Abstract one, and concrete has some public
methods that is required only inside this concrete repository, but repository calling or creation -
it is responsibility of some data manager
So, you create manager, implement method "getRepository() : RepositoryInterface" and then
you always needed to check "is it my repository or other one".
Currently may be solved with PHPDoc
@template syntax very well, but requires additional
argument in method signature to define class-string $classT to work enough
good.
2. And second case - more often case - is to create plain list of any other type... Common pain here
is to check that list using foreach everywhere is necceseary. If you just create
"typehint" for "array of something" - it kinda work, but still at the core level
it will be foreach everywhere, just without writing that code.
So suggested stuff is to create internal class that represent "list" or maybe ok,
associative, that can contain only one data type that MUST be declared. So you create "new
List<string>" and typehint just check is passed value an instance of List<string>
via simple if. Potential of this improvement is uncountable.