Fix "Array to string conversion" for Symfony 7.4+ compatibility#195
Conversation
|
Tests that are failing but your assumption about the type is correct as Thanks. |
|
@DonCallisto It's good, thanks for you reactivity ! |
|
I was wondering if it should be better to "decompose" the array instead of skipping it altogether. Reasoning not about that Symfony specific case where, maybe, it is fine either way, but more in general, I think it would be sensible to do so. WDYT? |
|
I understand your point of view. However, I see a few limitations with that approach.
Another alternative could be to json_encode the array values. This would preserve the data as a string, which is compatible with environment variables. However, the subprocess would still need to be aware that it needs to json_decode that specific entry to use it. |
We could still face them as we're not controlling
Not sure about that. I mean, I don't know how symfony will look after them and we don't need to care about it. You can see this as a "best effort" logic: instead of get rid of 'em, try to provide a sensible list. The more I think, the more I'm convinced we should not skip those values. |
|
I have updated the code to implement the array decomposition as discussed: decomposeRecursively: Instead of skipping nested arrays, this method flattens them into prefixed keys (e.g., APP_RUNTIME_OPTIONS_project_dir). formatValueForEnv: This ensures every value is a string. It handles scalars, converts stringable objects via __toString(). I hope this version works for you. |
|
I've just released a new version https://github.com/liuggio/fastest/releases/tag/v1.14.1 I was not convinced about carrying around "prefixes" for those arguments but I didn't had a strong opinion or specific use case to ask for a change. Thanks for your contribution. |
Description
This PR fixes a
Warning: Array to string conversionthat occurs when usingliuggio/fastestwith Symfony 7.4 or higher.The issue:
Since Symfony 7.4, the Symfony Runtime component exposes new entries in
$_SERVER, specificallyAPP_RUNTIME_OPTIONS. This entry is an array.When
EnvCommandCreator::executemerges$_SERVERinto the environment variables for the subprocess, it includes this array. Later, whenSymfony\Component\Processtries to start the process, it iterates over these variables and fails because it attempts to concatenate an array as a string:The fix:
I updated
EnvCommandCreatorto filter out any values that are arrays. Environment variables should fundamentally be strings; passing an array through the environment is not supported by the underlying OS/process components anyway.Changes
Liuggio\Fastest\Process\EnvCommandCreator::executeto skip elements where the value is anarray.