I have the following class,e.g.
class A{
public var1;
public var2;
}
now, I want to create an object of this class, and I do the following:
$a = new A();
$a->var1 = 123;
$a->var2 = 987;
Is there a more better way to do this, since at times there can be even 20 such variables inside the class. I am just looking for compacting the code, and a constructor is not being used for this class. The values for variables are not static (that is why no static keyword is used)
I am looking more for this kind of assignment we do for arrays:
$arr = array(
'var1' => 123,
'var2' => 987
);
Furthermore, how will I go around avoiding NullPointerException (which sometimes comes up when I try to send this object to a .Net enabled web service) - This is optional though, as I can atlst relate this to null variables inside the class, but not exactly sure how to overcome this error.