Can A member of A class be declared using another class, and the assignment degree to this member requires this function class & nbsp; A {& nbsp; var & nbsp; $ sun & nbsp; var & nbsp; $ sav & nbsp; false ;} can class & nbsp; B {& nbsp; & nb class members be declared using another class? do I need this function to assign values to this member?
Class
{
Var $ sun = '';
Var $ sav = false;
}
Class B
{
Var $ vo =;
Var $ tmp = 0;
}
Isn't that true?
So: class B
{
Var $ vo;
Var $ tmp = 0;
Function f ()
{
$ This-> vo = new;
}
}
In use:
$ Cls = new B;
$ Cls-> vo-> tmp = 1; // is this not acceptable? Using functions of class members?
Share:
------ Solution --------------------
$ Cls = new B;
$ Cls-> f (); // The value assigned by your vo attribute in this method!
$ Cls-> vo-> tmp = 1;
------ Solution --------------------
Class B
{
Var $ vo = A; // This is incorrect!
Var $ tmp = 0;
}
------ Solution --------------------
Reference:
Quote: reference:
$ Cls = new B;
$ Cls-> f (); // The value assigned by your vo attribute in this method!
$ Cls-> vo-> tmp = 1;
$ Cls-> vo-> tmp = 1; // It seems impossible for me to test the assignment?
Your code is probably wrong.
The following code is the same as your logic. it is executed and expected to have the same effect.
class A {}
class B {
var $attrV;
function setAttrV()
{
$this->attrV = new A();
}
}
$obj_b = new B();
$obj_b->setAttrV();
$obj_b->attrV->attrA = 'A';
echo '$obj_b->attrV->attrA=' . $obj_b->attrV->attrA;