8000 [DependencyInjection][3.3] Warning: stripos() expects parameter 1 to be string, array given · Issue #25245 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection][3.3] Warning: stripos() expects parameter 1 to be string, array given #25245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Phantas0s opened this issue Dec 1, 2017 · 4 comments

Comments

@Phantas0s
Copy link
Contributor
Phantas0s commented Dec 1, 2017
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.3

I have this bug which is related (I think) to some modification you did in the ContainerBuilder.

Warning: stripos() expects parameter 1 to be string, array given 
in /var/www/html/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php on line 1376

This is due to some environment variables I have which is an array. In the ContainerBuilder:

    public function resolveEnvPlaceholders($value, $format = null, array &$usedEnvs = null)
    {
        if (null === $format) {
            $format = '%%env(%s)%%';
        }

        if (is_array($value)) {
            $result = array();
            foreach ($value as $k => $v) {
                $result[$this->resolveEnvPlaceholders($k, $format, $usedEnvs)] = $this->resolveEnvPlaceholders($v, $format, $usedEnvs);
            }

            return $result;
        }

        if (!is_string($value)) {
            return $value;
        }

        $bag = $this->getParameterBag();
        if (true === $format) {
            $value = $bag->resolveValue($value);
        }

I think you need to put this condition

        if (true === $format) {
            $value = $bag->resolveValue($value);
        }

before this conditional:

    if (is_array($value)) {
            $result = array();
            foreach ($value as $k => $v) {
                $result[$this->resolveEnvPlaceholders($k, $format, $usedEnvs)] = $this->resolveEnvPlaceholders($v, $format, $usedEnvs);
            }
@nicolas-grekas
Copy link
Member

How did you create an env that is an array? Using defaults? Using the "json:" processor?
Anyway, would you like to submit a PR to fix it (with tests of course)?

@skluck
Copy link
skluck commented Dec 6, 2017

For us we get this issue when we have array parameters and env var parameters. They don't interact with each other, they are just both defined.

Heres a script I use to repro:

# test.yaml
parameters:
    example: '%env(RANDOM_VARIABLE)%'
    parameter_array:
        - '/path1'
        - '/path2'
services:
    test_service:
        class: 'Symfony\Component\Config\FileLocator'
        arguments: ['%parameter_array%']
<?php
# test.php
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;

require __DIR__ . '/vendor/autoload.php';
putenv('RANDOM_VARIABLE=testing');

$container = new ContainerBuilder;
$loader = new YamlFileLoader($container, new FileLocator(__DIR__));

$loader->load('test.yaml');
$container->compile(true);

$test = $container->get('test_service');

Symfony 3.3.x

> composer show

psr/container                1.0.0   Common Container Interface (PHP FIG PSR-11)
symfony/config               v3.3.14 Symfony Config Component
symfony/dependency-injection v3.3.14 Symfony DependencyInjection Component
symfony/filesystem           v3.3.14 Symfony Filesystem Component
symfony/yaml                 v3.3.14 Symfony Yaml Component

> php test.php

<< no output >>

Symfony 3.4.x

(Symfony 4.x has same results)

> composer show

psr/container                1.0.0  Common Container Interface (PHP FIG PSR-11)
symfony/config               v3.4.1 Symfony Config Component
symfony/dependency-injection v3.4.1 Symfony DependencyInjection Component
symfony/filesystem           v3.4.1 Symfony Filesystem Component
symfony/yaml                 v3.4.1 Symfony Yaml Component

> php test.php

PHP Warning:  stripos() expects parameter 1 to be string, array given in /testproject/vendor/symfony/dependency-injection/ContainerBuilder.php on line 1375

Warning: stripos() expects parameter 1 to be string, array given in /testproject/vendor/symfony/dependency-injection/ContainerBuilder.php on line 1375

@Simperfit
Copy link
Contributor

@skluck does the PR #25333 fix the issue you are facing ?

@skluck
Copy link
skluck commented Dec 11, 2017

Yep, with the change 3.3, 3.4, and 4.0 all seem to work as expected, giving the same results.

fabpot added a commit that referenced this issue Dec 11, 2017
… array as container parameter (Phantas0s)

This PR was squashed before being merged into the 3.3 branch (closes #25333).

Discussion
----------

[DI] Impossible to set an environment variable and then an array as container parameter

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #25245
| License       | MIT

When an environment variables and then an array is set as container parameters, an error is thrown (Warning: stripos() expects parameter 1 to be string, array given).

You can run my test without the fix in the Container builder to see it.

Commits
-------

484a082 [DI] Impossible to set an environment variable and then an array as container parameter
@fabpot fabpot closed this as completed Dec 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants
0