Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass single element of parameter, declared as array?

Tags:

php

symfony

I have in config.yml:

parameters:
    aaa:
        bbb: 'Example'

If I pass this in service:

AppBundle\Service\Service:
    arguments:
        $bbb: '%aaa%'

Then this is working well and I have array, but if I pass:

AppBundle\Service\Service:
    arguments:
        $bbb: '%aaa.bbb%'

Then I have error:

The service "AppBundle\Service\Service" has a dependency on a non- existent parameter "aaa.bbb". You cannot access nested array items, do you want to inject "aaa" instead?

Is possible to pass only one value?

like image 771
zison Avatar asked Sep 26 '17 09:09

zison


People also ask

How do you pass a single element of an array in a function?

If individual elements are to be passed as arguments, then array elements along with their subscripts must be given in function call. To receive the elements, simple variables are used in function definition.

Can we pass a single value out of an array as a parameter to function?

If you want to pass a single-dimension array as an argument in a function, you would have to declare a formal parameter in one of following three ways and all three declaration methods produce similar results because each tells the compiler that an integer pointer is going to be received.

Is it possible to send just one element of an array to a function?

Single array elements can also be passed as arguments. This can be done in exactly the same way as we pass variables to a function. This code appearing here is passing a single element of an array to a function: #include <stdio.


1 Answers

You have to have parameters like this:

parameters:
    aaa.bbb: 'Example'

with purpose to re-use like:

AppBundle\Service\Service:
    arguments:
        $bbb: '%aaa.bbb%'

Otherwise, you have to pass whole array, you can't pass single element from array.

like image 156
cn007b Avatar answered Oct 02 '22 09:10

cn007b