Search code examples
phplogginginterpolationpsr-3

PSR-3 interpolation


I am wondering what the exact use it for the interpolate function when you have a PSR-3 logger. I know how it works by looking at this reference:

https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#12-message

But so far I cannot seem to think up of a use-case for it yet. Why would you not simply interpolate it like you normally do? Instead they opt to use a context array with placeholders.

If somebody could tell me why this would be helpful, over just putting the variable straight in there I would be grateful.

Thanks.


Solution

  • I don't know whether I understand your question completly, anyways: Every method accepts an array as context data. This is meant to hold any extraneous information that does not fit well in a string.

    To replace every placeholder in the array we need a method, this is interpolate()

    PSR-3 | 1.3 - Context