Drop pass by reference from __construct()

Review Request #23 — Created Dec. 9, 2012 and submitted

pprkut
Lunr
master
lunr
While implementing the Service Locator I found that doing pass by reference with it is insanely difficult and beyond the point where it would be useful.
Since doing big projects without a service locator is a bit of a PITA, and we have a goal of making Lunr work independent of whether a service locator is used or not, pass by reference has to go for compatibility reasons.

That leaves some questions about unset(), that Olivier also raised in another review. So I did some testing myself and found that unset in 99% of all cases is behaving as it should.
If the object is instantiated separately and passed via a variable in the constructor:

$a = new sdtClass();
$b = new stdClass($a);
unset($b);

If there is an unset($this->a) in $b's destructor, it will only remove the local reference within $b. $a will stay usable after $b is destroyed. Whether $a is passed by reference or value makes no difference.

If the object is instantiated within the constructor call:

$b = new stdClass(new stdClass());
unset($b);

The the unset($this->a) in $b's destructor will also call $a's destructor.

So we can safely (again) use unset() on all properties in a class. It will work as intended.
Unit tests
Felipe
  1. Ship It!
  2. 
      
olivier
  1. Ship It!
  2. 
      
pprkut
Review request changed

Status: Closed (submitted)

Change Summary:

Merged with master
Loading...