Class as parametar of other class - how to pass values?

Need some help ant tips to understand and solve these case:

<?php class A { public $varA1; //type string public $varB; // type B function dispA(){ echo '$a->varA1 = '.$this->varA1.'
'; } } class B { public $varB1; // string public $varB2; // string function dispB(){ echo '$b->varB1 = '.$this->varB1.'
'; } } $b = new B(); $a = new A(); $a->varA1 = 'someA1'; $b->VarB1 = 'someB1'; $b->VarB2 = 'someB2'; $a->dispA(); $b->dispB(); //How to set up $a->varB? //This didnt work: //$a = new A( $b ); //$a->varB = new B(); //$a->varB1 = 'someAB1'; //There is function nedded to call witch takes argument of type A: //$result = foo( $a ); ?>

Tnx.

<?php class Person { public $genre; //string public $writer; //PersonWriter } class PersonWriter { public $name; //string public $age; //string } $person= new Person(); $writer = new PersonWriter(); //$person= new Person( $writer ); $person->writer = $writer; $person->writer->name = "Joe"."\n"; $person->writer->age = "44"."\n"; $person->genre = "PHP"."\n"; print_r($person); ?>
Sponsor our Newsletter | Privacy Policy | Terms of Service