Skip to content

Commit

Permalink
#208 - moving around docs about initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocramius committed Jan 22, 2016
1 parent 453bd66 commit a602900
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions docs/lazy-loading-ghost-object.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ or
$initializer = null; // if you use the initializer passed by reference to the closure
```

Remember to call `$proxy->setProxyInitializer(null);`, or to set `$initializer = null` inside your
initializer closure to disable initialization of your proxy, or else initialization will trigger
more than once.

## Triggering Initialization

A lazy loading ghost object is initialized whenever you access any property of it.
Expand Down Expand Up @@ -272,8 +276,14 @@ clone $proxy;
$unserialized = unserialize(serialize($proxy));
```

Remember to call `$proxy->setProxyInitializer(null);` to disable initialization of your proxy, or it will happen more
than once.
A method like following would never trigger lazy loading, in the context of a ghost object:

```php
public function sayHello() : string
{
return 'Look ma! No property accessed!';
}
```

## Proxying interfaces

Expand Down

0 comments on commit a602900

Please sign in to comment.