Hi David,

On 21 July 2016 at 16:51, David Rodrigues <david.pro...@gmail.com> wrote:
> This Feature Request is about the implementation of lazy statements.

This looks to solve a problem very similar to the one solved by the
'Memoize' annotation in HHVM -
https://docs.hhvm.com/hack/attributes/special#__memoize

However the memoize functionality seems a lot clearer to me, as it's
less 'magic'; it doesn't make accessing a variable actually call a
function.


Larry Garfield wrote:
>> However, that also means there's an enormous potential for race
>> conditions.

I think s/race conditions/circular dependencies/ probably explain the
problem more clearly.

> I can think about how we can handle this, but I need a real case
> where this problem can exists.

This code has a circular dependency:

class Foo {
    public $a, $b;
    public __construct() {
        $this->a = lazy { return 1 + $this->b; }
        $this->b = lazy { return 1 + $this->a; }
    }
}

$foo = new Foo;
echo $foo->a;

$foo->a can't be resolved until $foo->b is resolved, and $foo->b can't
be resolved until $foo->a is resolved.

Although that is obvious in a trivial code example, when trying to use
a magic feature like this in complex code, where the circular
dependency involves, say, 10 items, then it become very hard to reason
about the code.

Because the 'memoization' of functions is less magic, it is much less
prone to this circular dependency problem.

cheers
Dan

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to