Welcome Guest, Not a member yet? Register   Sign In
Public variable in Class VS config item?
#1

[eluser]solid9[/eluser]
Hi guys

What is the advantages/disadvantages of using config item
than Public variable in class.

By the way currently I am experiencing problem using the
public variable in class. Whenever I go back and forth
with method the variable that I declare as public in
class don't work often. How do I fix this?
What is the alternative?

Thanks in advanced.


#2

[eluser]JoostV[/eluser]
Typically, you use config for general settings that you need to use in different locations throughout your application. Typically you declare a variable inside of a class if it is clearly bound to that class. The rest is really a question of preference or coding standards your team uses.

As for public variables, if you declare them at the top of the class they are always accessible.
Code:
class My_Class {

public $my_var = 'Foo';

function some_function() {
  echo $this->my_var;
}
}




Theme © iAndrew 2016 - Forum software by © MyBB