Is it possible to deploy variable in class php?

Is it possible to deploy variable in class php?

<?php
class get_variable {
    echo $deploy_variable;
}
$deploy_variable = 'Hello World';
$foo = new get_variable;
?>

It is, but you really should not do that.

What problem are you trying to solve?

At the VERY least, make it a parameter of your constructor, not relying on a global variable…

1 Like

Thank you for answering!
I need to call this class 20 times with New get_variable
could someone make an example?

2 Thank you for answering!
I need to call this class 20 times with New get_variable
could someone make an example?

Why? You can’t “call” a class. You can create a method is a class and call that. Is that what you mean?

What is the actual problem you’re trying to solve? I don’t mean the solution you’ve come up with, but high level, what are you trying to do?

Isn’t there any way I only call once?
please give me how to do it just once

I don’t know what you mean. What are you trying to do? Besides confusing me I mean …

If by “deploy” the both of us define it similarly my guess is something like

Have this class take care of prerequisite values that are needed. The number and type of variables should be fluid.

i.e. kind of an “initializer”?

i need to deploy new get_variable 20 times
with value $deploy_variable = ‘Hello World’; of the different variable in all

So a for loop would probably do it then? Either give each instance a name in an array, or use a variable variable name?

OP, what exactly is the real problem you are trying to solve with this code attempt?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.