Can a member of a class be declared using another class? does this function need to assign values to this member?

Source: Internet
Author: User
Can A member of A class be declared using another class? does this function be required 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?









Reply to discussion (solution)

$ Cls = new B; $ cls-> f (); // The value assigned by your vo attribute in this method! $ Cls-> vo-> tmp = 1;

Class B
{
Var $ vo = A; // This is incorrect!
Var $ tmp = 0;
}

$ 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?

Class B
{
Var $ vo = A; // This is incorrect!
Var $ tmp = 0;
}

So: class B
{
Var $ vo;
Var $ tmp = 0;
Function f ()
{
$ This-> vo = new;
}
}

In use:
$ Cls = new B;
$ Cls-> f ();
$ Cls-> vo-> tmp = 1; // Can this be true? You must use the member function to assign values.


$ 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.
 attrV = new A();}}$obj_b = new B();$obj_b->setAttrV();$obj_b->attrV->attrA = 'A';echo '$obj_b->attrV->attrA=' . $obj_b->attrV->attrA;

Thank you, everyone upstairs. there is a semicolon in the program!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.