•  
      request #35866 Have an equivalent to Dispose pattern in PHP
    Infos
    #35866
    Joris MASSON (jmasson)
    2024-10-14 17:20
    2024-01-23 14:59
    37468
    Details
    Have an equivalent to Dispose pattern in PHP

    The Dispose pattern (see [0]) can be useful when dealing with persistent resources that need to be freed, closed or cleaned-up. A common mistake is to forget to run this clean-up operation, or to miss it when an exception is thrown, or when a certain branch of the program is taken. The dispose pattern helps with those mistakes by ensuring that the clean-up operation is always done at the end of a function.

    TypeScript 5.2 (see [1]) introduced it at the language-level. It would be useful to have it also in PHP (at a library-level however). For example, it could help us with database integration tests: it is easy to forget cleaning up data, and since the same database is shared by all tests, it can quickly lead to flaky tests.

    [0] https://en.wikipedia.org/wiki/Dispose_pattern
    [1] https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management

    Dev tools
    Empty
    Empty
    • [ ] enhancement
    • [ ] internal improvement
    Empty
    Stage
    Joris MASSON (jmasson)
    Closed
    2024-01-24
    Attachments
    Empty
    References

    Follow-ups