Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94642 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86697 invoked from network); 23 Jul 2016 10:06:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Jul 2016 10:06:51 -0000 Authentication-Results: pb1.pair.com header.from=danack@basereality.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=danack@basereality.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain basereality.com from 209.85.161.176 cause and error) X-PHP-List-Original-Sender: danack@basereality.com X-Host-Fingerprint: 209.85.161.176 mail-yw0-f176.google.com Received: from [209.85.161.176] ([209.85.161.176:34975] helo=mail-yw0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7F/CD-24343-AB143975 for ; Sat, 23 Jul 2016 06:06:50 -0400 Received: by mail-yw0-f176.google.com with SMTP id j12so116665028ywb.2 for ; Sat, 23 Jul 2016 03:06:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basereality-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=SoBFFnVML5N6ipQvkxqcT5iYYg6ByBvJzsbKjgEF4KM=; b=shpQW28Cm7mqv6OTxBtqun4pSIhJ1TZb6oBCPF6TrDMMjz076UVrv77N8AhXNQ41Vt FasarUPV3+bN09eDjue7H5We4ShhMQVngdAoTksfDkhdhd/ABKO+JC6tSEwqHnfhj0FL WE91S7mgF4w6LNtuJI9cQdk0BWkUdzIp+7duvYdHZ0Hj2HcHYPgVztA/MVy+sA1PqY1H gZL32iicaA6PjvwHXuO6Jd/VP4KgbZnCQRVld4WszPG1xHPcLF0Qm8XyW3uhzSfY9o4a l5DQI+NSs8I+zizSQEqd1prdqg782qsMZDQxqPzXRcY9OK6mJ2ylEAWcZUzxzsVAYGuL lgVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=SoBFFnVML5N6ipQvkxqcT5iYYg6ByBvJzsbKjgEF4KM=; b=T5i/0wliYOwvc9L6pLcUbSrZyWZ2aF49/Cd4Gd36nJ4FQrOGwOckyJAHs0xJHiWawZ VpLqxVcofuvlLhVvaKpSnJd2eTZ2VORbuLCNq50Dcb7dfg1jY+5wrFfQTv+8oG0oe537 CNivH7+Cae4IKZQ/1Z6V8RlApNxfXNye09QZEc72ivsJ5bdZPG8UUsI8+WYdcR5QG5Vu fa4AW5ldTyGuaRfpPTdqxuXw637ivcwMRJv2Tg4R8+HPzwBo+g+zmgcdOUDbhA0m8HRh r3ZjrIADsFODN4bPgeokkiEJ3oLLhWEpCN3pafMc0+MynzBJpW78merHqne6S55aqc76 b2aQ== X-Gm-Message-State: AEkoouuYT8nfTVlYgG+NzIiRJr7t93fIZGTf/KzToSiBS+mqU97cQ1FGzZehNmzDkZNBbedMcAjTaUdlvvalIQ== X-Received: by 10.129.51.215 with SMTP id z206mr6999948ywz.251.1469268407544; Sat, 23 Jul 2016 03:06:47 -0700 (PDT) MIME-Version: 1.0 Received: by 10.37.230.132 with HTTP; Sat, 23 Jul 2016 03:06:47 -0700 (PDT) X-Originating-IP: [78.144.121.211] In-Reply-To: References: Date: Sat, 23 Jul 2016 11:06:47 +0100 Message-ID: To: David Rodrigues Cc: PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] RFC: lazy statements From: danack@basereality.com (Dan Ackroyd) Hi David, On 21 July 2016 at 16:51, David Rodrigues 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