filecage/creator

Factory result of interface factories has insufficient caching

Closed this issue · 0 comments

Affected Creator Version

0.8.0

Reproduce Scenario

<?php

interface FoobarInterface {
}

class Foobar implements FoobarInterface {
    function __construct() {
        echo 'Hello ';
    }
}

$creator = new Creator\Creator();

$creator->registerFactory(function() { return new Foobar(); }, FoobarInterface::class);

$foobar1 = $creator->create(FoobarInterface::class);
$foobar2 = $creator->create(FoobarInterface::class);

if ($foobar1 === $foobar2) {
    echo ' World!';
} else {
    echo ' Fail!';
}

Expected Output

Hello World!

Actual Output

Hello Hello Fail!