Is it possible to deploy variable in class php?
<?php
class get_variable {
echo $deploy_variable;
}
$deploy_variable = 'Hello World';
$foo = new get_variable;
?>
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âŚ
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.