A member of a species can be declared with another class, is this function required for the assignment of this member?

Source: Internet
Author: User
Can a member of a class be declared with another class, and this function is required for the assignment of this member?

Class A
{
var $sun = ';
var $sav = false;
}

Class B
{
var $vo = A;
var $tmp = 0;
}

Isn't that right?

That way: Class B

var $vo;
var $tmp = 0;
function f ()
{
$this->vo = new A;
}


In use:
$cls = new B;
$cls->vo->tmp = 1; Can't you do that, too? Do you use the function of a class member?








Share to:


------Solution--------------------
$cls = new B;
$cls->f ();//Because your VO attribute is assigned in this method!
$cls->vo->tmp = 1;

------Solution--------------------
Class B
{
var $vo = A;It's not right here!
var $tmp = 0;
}

------Solution--------------------
Reference:
Quote: Reference:

$cls = new B;
$cls->f ();//Because your VO attribute is assigned in this method!
$cls->vo->tmp = 1;



$cls->vo->tmp = 1; I'm testing this assignment as if it's not possible.

Your code estimates are wrong to write.
The following code is the same as your logic, and executes as expected.
 
  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;
  • 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.