Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104073 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 80644 invoked from network); 3 Feb 2019 21:58:33 -0000 Received: from unknown (HELO mail-io1-f41.google.com) (209.85.166.41) by pb1.pair.com with SMTP; 3 Feb 2019 21:58:33 -0000 Received: by mail-io1-f41.google.com with SMTP id s22so10129818ioc.8 for ; Sun, 03 Feb 2019 10:39:15 -0800 (PST) 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=MDbJ0QzCZrckg5jnei6q+566q74I30Wl8LTCqpwgIM0=; b=cE3GeL/Kl+4At1k7fFFwnsfclwgzmnBMid6s7OHGpallMstf+AsIVlR0pGxbLWUk/2 q7KRFkTpfn+t+ct+6KOCytnr6fwLnJneS+bEOJyP4ahEJA9/II5JWP1gNrIlENM/pPr7 YUqgonXbxN8ok8hlcE61zWtGgv7pps26S4HmWLgU+o0VExV+2DQeZN+0KtZemAF3lE9G bXY8sEYrI9Wr35KM35hmEt9Ucvb7qXO9KEWPmt6ZzaEg5f1NmOpAK/LE3WA/13HSvbOK 3bbipUInU8TNZyO+l4NBIIsMzARv6H6ogv8ETaIz7myXGddLeAQ+FOT8Bh2RvZaZ7bQ6 S1iw== 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=MDbJ0QzCZrckg5jnei6q+566q74I30Wl8LTCqpwgIM0=; b=O0VEylNNOAymerQkINNN/kBBPo07mrhfiYEyaEWLdXCR530C+KsJSqbKagIdRXczlH Le27ZhI004+CJDSl9RKQmPekv6DQwUzB35GHoS6+kc5BHC3g0dI899hi/URmZclLSIv7 ye9gPB89K1yLi0UBDCyfxgKbq692mnuVheLm9uLj8qlz9fgdDmBNI8zCgT0+XVDgSTI/ ODOArgm8oVcaImS03XExM/3yUXsGWDbaJ8RqQeNv3Wvx3Hm00jD4nZP0oyg23SMY7q4l quV73x1R73jufxfxdkSLNEV6MTl9CTaimriXS5sBvWJtjJB8KKX68NACAUmIuw9rfoi9 N7vg== X-Gm-Message-State: AHQUAuabeW0O9si0+oX924X4yAhFZxoHbbYyDDPxsZ0Vp8511a5MRupW +9jJ4Vsy7rS0BHdl0rXJxG20q2kASlepUCu1ZI4xcIQI X-Google-Smtp-Source: AHgI3Ib3382YyTsxdpSe9Lq0G7h4q8zxHJTD4ZAon7HEnK+7RDMjlUYfy6C2yr4EU1y4Dr2YrXSiAzWc0jK9MA3sH7k= X-Received: by 2002:a6b:b556:: with SMTP id e83mr30697396iof.195.1549219154888; Sun, 03 Feb 2019 10:39:14 -0800 (PST) MIME-Version: 1.0 Date: Sun, 3 Feb 2019 16:39:03 -0200 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary="000000000000680e59058101b12b" Subject: PHP 8: Method Overloading, The Ressurection From: david.proweb@gmail.com (David Rodrigues) --000000000000680e59058101b12b Content-Type: text/plain; charset="UTF-8" Hello everybody! I know that method overloading was discussed on past and because a lot of reasons it was declined [1]. I think that it should be considered maybe for PHP 8, but for now I would like to suggest a different implementation. Because of a stronger support to parameter types that PHP has now, I think that is possible make this process more faster than before by handling it only in case of exceptions. I wil explain better. The biggest problem that I see about this topic is the loss of performance, but I think that it could be avoided by create a new keyword "overload" that should be applied before methods that could be overloaded. For instance: overload function sum(int $a, int $b): int; overload function sum(float $b, float $b): float; In this case, when call a method PHP could identify if it have a overloaded implementation, so ONLY in this case it will reduce performace to decided which implementation it should call. I don't know how PHP could treats it internally, but when overload keyword is identified, I think that it could generates a hash like "sum/int,int/int" and "sum/float,float/float" (method name, parameters types, return type). I don't know. So when method is called, it should convert the argument types and create a similar hash, making possible to identify what overloaded method should be run. It seems slow, but I think that the opcache could simplify the next operations to connect directly the call to the correct overloaded method. Please, tell what do you think, because I really wants method overload on PHP 8 or before. Currently we should do some code hacks to make it possible that certainly is slower than a native implementation. Thanks! [1] https://marc.info/?l=php-internals&m=121397217528280&w=2 -- David Rodrigues --000000000000680e59058101b12b--