Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94693 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58178 invoked from network); 25 Jul 2016 03:46:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Jul 2016 03:46:51 -0000 Authentication-Results: pb1.pair.com header.from=david.proweb@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=david.proweb@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.182 as permitted sender) X-PHP-List-Original-Sender: david.proweb@gmail.com X-Host-Fingerprint: 209.85.220.182 mail-qk0-f182.google.com Received: from [209.85.220.182] ([209.85.220.182:32843] helo=mail-qk0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FF/66-05797-8AB85975 for ; Sun, 24 Jul 2016 23:46:50 -0400 Received: by mail-qk0-f182.google.com with SMTP id p74so145896251qka.0 for ; Sun, 24 Jul 2016 20:46:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=zBwhzzZB8/3n2oBRgocTAeFEfud9MFs9vcfaaz00fFY=; b=oB0Duy10QzTiQ9FFsDsJBDR88m8LRuBQEQdjohIP9fl1JRBj+SKxph+ohbuzvHuDxP qb8458X+1MGuLCt3O8nhmZOzfhwDKGoNIHdVrvPU7csV/09sAhSrdypsbR/IdjQ+wXHZ C+jCxkBoWlzFAvR1jUEW7gkLaDPKRS0EoS4C1KfnlAj6afsmSICD9wAik/zFONyd9Zh1 t6rvFqnGidMnvROicPmoRn+HXRTGH1IKbBh1gcJ44WanWcOVoZtamzRWoo3hYMkLvSuJ LfBGc8Ph+KX/FkDGIGizmwZbdlj+HgYMFY6kTN6DURHleyHYbYO7ixsVL6zfsqvK17yx 9n8g== 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=zBwhzzZB8/3n2oBRgocTAeFEfud9MFs9vcfaaz00fFY=; b=DvsnI4/I0BVYxZUzaiUiIdPCeRtg7Z8x4boTkUUkc7sJiModj5Dkt3uDZGI4BGnNVz 4qkgQNnQqYQnKsTnsXrBJ7aagImn0N3pVBK5Yb+7gOUvWmPzNYL+NDbqOLoa0yDYnyJB 1i24pfox00xKW9uzQlHylGYMH0u+7TcoAq3FMNsFkSSltxklCw7VkY/d3dPIoi1lNLrB Pn3B9+srzGFnYYoUq+dBfP69hPGWi/Jc7okoElvVI6pon4ZxMT9j+yCB6hpgT61hmGSo r526kbA1b2D0h8bZa+sNKaYN4tjVVcDYa7ECN9I/g1d1AV5Nc6jObzMyA7fuUxqWitiG tuNQ== X-Gm-Message-State: AEkooutN3KuaVWZFPpe/1tu02rfNtXTEFXNZMy8az+j3Fl33V9qHX1pDCG18sQZnj5H+2skwfKkARH8jsry1Xg== X-Received: by 10.55.170.20 with SMTP id t20mr20708516qke.162.1469418406252; Sun, 24 Jul 2016 20:46:46 -0700 (PDT) MIME-Version: 1.0 Received: by 10.55.45.67 with HTTP; Sun, 24 Jul 2016 20:46:26 -0700 (PDT) In-Reply-To: References: Date: Mon, 25 Jul 2016 00:46:26 -0300 Message-ID: To: Dan Ackroyd Cc: Stanislav Malyshev , PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] RFC: lazy statements From: david.proweb@gmail.com (David Rodrigues) Dan Ackroyd wrote: > Yes, but the difference is in the surprise factor. > > Two functions having a circular dependency ==> not too astonishing, > and easy to think about. > > Reading the value of a variable having a circular dependency ==> give > up programming to become a farmer. Okay, so we can avoid circular dependencies (in sense of find where a circular dependency occur) by creating a progression system over lazy objects. Something like: Lazy { progress { DEFINED, EXECUTING, FINISHED }; statement } For instance, when you defines a lazy statement, it states is set as "defined". When you starts execution over it, it changes the states to "executing". After it finish, it change states to "finished". This last state is the final value of variable, basically. So, in case of a lazy statement be called on "executing" phase, it should throw an error. For instance: $b = null; $a = lazy use ($b) { return $b; } $b = lazy use ($a) { return $a; } In this case, both $a and $b are on state "defined". echo $a; When I call $a now, it set states to "executing". In this case, it'll try read $b that is lazy too. $b is now "executing" too. Now $b will try to read $a, but $a already is "executing" So PHP should throw an error like "cyclic execution on line x". But in all way, lazy statements should not be used on all places I should not substitute default variable, mainly because it should be less performatic (not too much, I guess). Lazy statements should be used only in case where the variable contents is very complex (high cost) and very few useful in all requests. And where methods or functions is not too viable. Example: class Foo { public $something = lazy { // do complex things. return $complexValue; }; } $foo = new Foo; $foo->something++; Instead of: class Foo { private $something; public function getSomething() { if (!$this->something) { // do complex things. $this->something = $complexValue; } return $this->something; } public function setSomething($value) { $this->something = $value; } } $foo = new Foo; $fooSomething = $foo->getSomething(); $fooSomething++; $foo->setSomething($fooSomething);