Nelmio\Alice\Definition\Object\SimpleObject::withInstance PHP Method

withInstance() public method

public withInstance ( object $newInstance ) : self
$newInstance object
return self
    public function withInstance($newInstance) : self
    {
        $clone = clone $this;
        $clone->instance = $newInstance;
        return $clone;
    }

Usage Example

Example #1
0
 public function testNamedConstructor()
 {
     $reference = 'user0';
     $instance = StdClassFactory::create(['original' => true]);
     $originalInstance = clone $instance;
     $object = new SimpleObject($reference, $instance);
     $newInstance = StdClassFactory::create(['original' => false]);
     $originalNewInstance = clone $newInstance;
     $newObject = $object->withInstance($newInstance);
     $this->assertEquals(new SimpleObject($reference, $originalInstance), $object);
     $this->assertEquals(new SimpleObject($reference, $originalNewInstance), $newObject);
 }
All Usage Examples Of Nelmio\Alice\Definition\Object\SimpleObject::withInstance