I'd like to use a simple function in Symfony 4, something like this :
src/Service/Utils.php
<?php
namespace App\Service;
/**
* @param string $attr
*
* @return bool
*/
function attributNilTrue($attr): bool
{
return json_encode($attr) === '{"@attributes":{"nil":"true"}}';
}
some/other/file.php
use function App\Service\attributNilTrue;
if (attributNilTrue($foo['bar'])) {
// Do something...
}
But I get the following error:
The autoloader expected class "App\Service\Utils" to be defined in file "/var/www/interop/vendor/composer/../../src/Service/Utils.php". The file was found but the class was not in it, the class name or namespace probably has a typo.
Is there a way to do that without having to create a Utils
class?