M
M
masimka2017-11-04 15:08:49
PHP
masimka, 2017-11-04 15:08:49

What is the best way to make a variable handling method, if, switch, variable?

There is a module that prepares the content that came from the user to the module in the form of variables, depending on the type of content, you need to use one or another module.
Data is coming:

$json_data = 
{"mod_type":"text_block", "blocks":
    {
        "block":"asdasd"
        "block2":"asdasd"
.....
    }
}
$arr_mod_type = json_decode($json_data)

Depending on the value of the mod_type variable, I want to apply the module for processing bypassing the switch or if's.
Namely How is it customary to do or what is it called? Or all the same, do it through a switch so that if there is no necessary module, the default condition is fulfilled?
STATIC::mod_{$arr_mod_type['mod_type']};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav B, 2017-11-04
@S_Borchev


STATIC::mod_{$arr_mod_type['mod_type']};
how does is called

shitcode.
if there is a way not to refer to a method \ field by name, then in 90% of cases it is necessary not to refer.
I don't know what you mean by module.
this is probably an erroneous situation, so handle it as an error and not quietly do some kind of action.
however, little is clear from your description, so it is difficult to advise something.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question