Good day everyone. For one of the projects, my task is to make a LinQ-like selection of data from the list object. Actually, I would like to abstract lists as much as possible, but at the same time not to lose such a wonderful function as autocompletion during selection. Actually, in order to abstract this business, an object of the sheet itself is needed, which in the constructor would accept the type of data it will rely on. Attention, question =)

  1. How to make it more concise? If you pass a string with the name of the type / class, there is a high probability of a handshake during initialization (the project is not done by me alone) + there is no auto-completion

  2. Having obtained the type of stored objects, how can I pass it to the parameters of PHPDoc?

I admit that the decision may be non-trivial, but so far there are no ideas.

Thank you very much!

  • Make an example of what you are trying to achieve, so it will be easier to understand what you need. - Bookin

2 answers 2

Well, for example, we have a class SomeType and a class Dictionary, which stores objects of the abstract type. During initialization, I would like to give it the type that needs to be stored.

For example (pseudocode):

// Конструктор класса public function __construct($type) { $this->type = $type; } // Создание объекта класса из реализации $dictionary = new Dictionary(SomeType); 

So that the dictionary can store only objects of the class SomeType

Next, in the PHPDoc dictionary methods:

 /** * *@param $key string * *@return %тип из $this->type * */ public function get($key) { ... return $this->objects[$key]; } 

    If there are few types, declare a class with parameters:

    public class Dictionary($param1 = null,$param2 = null, ... ,$paramN = null)

    And when you call to transfer the desired type, for example:

     Dictionary($param4); 

    And directly in the class itself to implement the overload