There is for example a procedure / method / function which retrieves data from some table in the database. Suppose it selects all fields and returns a list of objects with magic properties that have the same name as the table fields.

Due to the fact that we do not see these properties through the intellisense of our IDE in which we work when writing client code, we may be mistaken in the name of the property and the program will work incorrectly but it will not generate an error. There is such a practice, to create classes for storing such objects with normal non-magical properties and to write information from the database when reading into objects. Well, in fact, then you can write a program using intellisense and be sure that there are no errors.

The question is, is there a name in the terminology of the PLO or some other such classes / objects?

  • 3
    For example, DTO is an object without methods, just a description of the structure - Maxim Timakov
  • Thank you, I think that it is quite possible to issue in the form of an answer, you helped me. - Dmitriy Gvozd

2 answers 2

For example, DTO is a class without methods, just a structure description.

DTO is convenient to use with PDOStatement :: fetchObject / PDOStatement :: fetchAll (with the parameter PDO :: FETCH_CLASS)

    And what is phpDoc not for you?

    /** * @method $this instance($name) */ class Result { } /** * @property Result $test */ class Magic { } $magic = new Magic(); $magic->test->instance('Hello')->instance('phpDoc'); 

    Update

     //Класс описанный где-то в недрах vendors class Magic { } #region Documentation /** * Наш результат для примера * * @property int $x координата по оси Х * @method instance($name) */ interface IResult { } /** * Магический класс, попробуйте его * * @property IResult $test */ interface IMagic { } #endregion /**@var IMagic $magic */ $magic = new Magic(); $magic->test->instance('Hello'); $magic->test->x; 
    • Well, if you take and can convince the manufacturer of the framework to follow your methods, it may be suitable. The question was general, how exactly such classes are called, and not how to solve this problem differently. - Dmitry Gvozd
    • Updated code. So in this and the beauty of the same phpDoc that you do not depend on the manufacturer of the framework. You can describe your components for example. And if you haven't switched to PHP7 yet, the data type description even helps a lot. I usually do the documentation through interfaces. - Ninazu 4:21 pm
    • I usually write programs that other programs write. - Dmitry Gvozd