Feature request from bentideswell, posted on GitHub Jun 22, 2016
The function returns a \Magento\Framework\Phrase object that when echo'd, is converted to a string via the toString method. This breaks several integrations I am working on and also doesn't work properly with json_encode (its saved as an object rather than a string).
Is it possible to have have this method return a string? The majority of time this method is used, it will be echo'd straight away, meaning the object isn't required anyway. A second function could be created that returns the object and the __ function could call this second function and cast the result to a string.
Here is a rough example:
function __O()
{
$argc = func_get_args();
$text = array_shift($argc);
if (!empty($argc) && is_array($argc[0])) {
$argc = $argc[0];
}
return new \Magento\Framework\Phrase($text, $argc);
}
function __()
{
return (string)__(func_get_args())
}
This is needed as the __ function cannot be overwritten or extended like all other publicly available methods in Magento.