Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103265 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 43371 invoked from network); 26 Sep 2018 23:38:38 -0000 Received: from unknown (HELO mail-it1-f173.google.com) (209.85.166.173) by pb1.pair.com with SMTP; 26 Sep 2018 23:38:38 -0000 Received: by mail-it1-f173.google.com with SMTP id m9-v6so4557354ita.2 for ; Wed, 26 Sep 2018 12:46:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=0RPd+l9BiJ74T4Lcg8+hSsfe6nTXXxwF0BehQ/KEfxU=; b=QIuSz+AcqdHBwntFFPTF/dgLqXn8+KgXHmGmFs0skSZ3fCHyN6nSllYX6Sayxxfz2j LWwXIvPrwNCB+8DuTO+fv5EOXPFEZvyae1wvwMWg1EB85Rdo0RW3It/Gv+7o409AJ293 XUeIviF6AOrxVD7SrkA6ynAIvzMXcM3WHOqJgdJ6Kh2TY6a/VHjBVxldR6EkIgLsVPFg w2Pw+GZ+olNN0WIzW9P02D0Pk7DWPTHdlrEYHifeo6lFaiIUMR+Si63SRDp9wira/Exj hBiAI+LBMvbDvtm7StdRXJJbNFUIFZVakLGzzpKb3cinCMm4LoMYvSiEIGTKr+GlpIG9 WeoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=0RPd+l9BiJ74T4Lcg8+hSsfe6nTXXxwF0BehQ/KEfxU=; b=AGfLF6VHE+veZl6uSsKrSUOJDXiXekBC0ha54ayrkPOIy3NITqM8pie8ubRdp5Dow9 0jkDOunPjQlwb0X+Y1jysjF/RRFxi0AjsbOIJynuzi1rYhOXE/HXKJA5jcmR5tyZbDpN wlwjcPKSfCjOvk8F/VzPUa2CxYv0icQztRDYxl2dMywiBjxsurSDCFgj0C3svVoFw1Cr pChMvWstF4rKIIx2gueNlGuJCIpj3Z83TW69hK41Mg+19HdydKKZMcRF1BK155fE7bdE jxGe9WNvjuk+qNh7e71jgiL6fDM5iCNXAN/kn1Gd3RoGE2ImHF9MXmkRyMyqL9MM2iN2 S62A== X-Gm-Message-State: ABuFfog0u3CEh0o/58X0gZIOikRlNj1YxxScSGEL7Fy/uG/MXKm/cMFx isToyX21q5LYmDNKQFFvpQhbKlt6Zvbb8aqzt8XMYQ4k X-Google-Smtp-Source: ACcGV62mitJczFkDRoaAkiFsKbLDepHT4a+BZHISIXAAY/acIYI0yA/D2BWdVbnrNT1JhBeSNKtKPz1C02HOF3i+V6A= X-Received: by 2002:a24:4c2:: with SMTP id 185-v6mr6296827itb.11.1537991208908; Wed, 26 Sep 2018 12:46:48 -0700 (PDT) MIME-Version: 1.0 Date: Wed, 26 Sep 2018 16:46:37 -0300 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary="000000000000acbe3f0576cb7b34" Subject: Interruptions From: david.proweb@gmail.com (David Rodrigues) --000000000000acbe3f0576cb7b34 Content-Type: text/plain; charset="UTF-8" I do not know if I can get the same result with the current PHP features without taking many turns. So I thought of a feature that I'm initially calling "interruptions" (similar to those that occur on a CPU). Nowadays we have the Exceptions, which stop the execution of a function and initiate a process of "catch" and treatment of the same. So I thought of something similar, but did not break the execution flow, allowing reactions to depend on what was happening inside a function. It would basically work according to the following flow (the square brackets number is the execution order): function sum(int $a, int $b): int { [2] interrupts with new SumInterruption($a, $b); [5] return $a + $b; } interruptable { [6] $sum = [1] sum(1, 2); [7] printf($sum); } [3] catch (SumInterruption $interruption) { [4] printf('Calculating: %d + %d = ', $interruption->a, $interruption->b); } Using current PHP features I can do like that: https://pastebin.com/Bci6BBfi Note that all code will be executed, and the interpection will only redirect temporarily the execution flow to the "catch" block, then will back to "sum()" block to return the sum. Like Exceptions, an Interruption will traverse the code execution tree until find a interruption catch block, but if it doesn't exists, just not will happen (or maybe throw InterruptionNotHandledException or something like it). In one of my real example cases, I have a code that could be manipulated by another method. Currently I need argument the self instance to this method, so it could run another method from the caller method to make some adjustments, which is a bit confuses. I hope you understand my point, and I am open to discuss that. Thanks! -- David Rodrigues --000000000000acbe3f0576cb7b34--