07-27-2009, 04:58 PM
|
#1 (permalink)
|
|
The Wanderer
Join Date: Jul 2009
Posts: 5
Thanks: 0
|
Object Association doubt.
Hi. I was wondering which one of the samples below would be right to set as object association.
===snippet 01===
PHP Code:
$p1 = new Person(10, 'John Doe', '31/07/1967');
$a1 = new Account;
$a1->accountOwner = $p1;
var_dump($a1);
unset($a1);
echo isset($p1) ? '$p1 isset' : '$p1 is not set'; // Person is still set
=============
===snippet 02===
PHP Code:
$a1 = new Account;
$a1->accountOwner = new Person(10, 'John Doe', '31/07/1967');
var_dump($a1);
unset($a1);
// both Account and Person are unset here
=============
In snippet 01 objects Person and Account are created separately and then I reference assign Person to Account, $a1->accountOwner = $p1;
In snippet 02 I reference assign Person to Account, $a1->accountOwner = new Person(10, 'John Doe', '31/07/1967'); so that I don't have $p1 explicitly assigned.
The doubt is: which one is considered to be Association?
Thanx in advance 
|
|
|
|