Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106835 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 11843 invoked from network); 2 Sep 2019 20:30:36 -0000 Received: from unknown (HELO mail-qt1-f170.google.com) (209.85.160.170) by pb1.pair.com with SMTP; 2 Sep 2019 20:30:36 -0000 Received: by mail-qt1-f170.google.com with SMTP id t12so16401743qtp.9 for ; Mon, 02 Sep 2019 11:04:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6bTj9S7rjoi+PTHBNjBz8hawCo3OLz7XqmQ+wLT1WOc=; b=TrxNRT8CBVQOt2IHP1ncLVhrTwognRYuJCsE1Hr+y7jsYMDZgSGwQ/fJFpgNxRXq10 0XjAhEh2xz59bQqsAvd8sPgV85eAAWO2lsWc5VLbjsOvww5s7gxHefiOUSvuutx0vbNp C0OoFqFF44wQjF/o9znKEl0sFE+z8jm0flQBZViDl/QnHEotIkzG6o9ARthV/wxZlmid 4B5yDLEVnbmASwHEFE+D55yBqcU+DIm06iFnP0tGRQR+LY372GVbLebmcXFvqAtUUehW /grNETz+HRV/XKWXbwWgqojSl1jMuGgM/gY9fOi/EjySBjfAoJcrgDfeuv0cdzQQd5uk 06ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6bTj9S7rjoi+PTHBNjBz8hawCo3OLz7XqmQ+wLT1WOc=; b=Y7eg303lMXlATR6wUJn70IBkwYOd7L0Tryqs0T1ghx9RjgLAtMZkbRKEMRIh1ewnc5 lc2fIAhKVjDWBwxud9T0CLn28M9JX6P/P71rVIUSfl9iCFEzu27twGoZ4ANQyyhEr1SP 7xTgtB/8mkGt1rKD6S3O+5pDE/fgPTttJwcf9LARYB1yefBrjN8+zy38cHwN1bF9+81p f0WUYrHwr+nUV4WQ7daWXswdzdNIakncs5AeH6nEgA571YaG9qyrSk1SYenXZPfX79K9 Xllwts2atXKf6sT6Ay6jC65Yieh4t4weMJUpkAZpqTNOI4EzbdfCw816d2yEKUH1B3jI NG9Q== X-Gm-Message-State: APjAAAV90NHZaEjtPg8yoC4XiBe/5iWWENL7YMyxUv9IO/St3mPRXrFM BcwID2qJxXWZYvDqoRRddKzBfW4e6Gk= X-Google-Smtp-Source: APXvYqwLRFdD5g4tPK76Gf5tWdlxuY5J96xhZxq90qFM0JH0lLfW3Dk80jIldVy0PN10AFfNJNrJtw== X-Received: by 2002:ac8:460b:: with SMTP id p11mr28317129qtn.93.1567447443246; Mon, 02 Sep 2019 11:04:03 -0700 (PDT) Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com. [209.85.222.169]) by smtp.googlemail.com with ESMTPSA id e17sm7667797qkn.61.2019.09.02.11.04.02 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 02 Sep 2019 11:04:02 -0700 (PDT) Received: by mail-qk1-f169.google.com with SMTP id q203so3982759qke.1 for ; Mon, 02 Sep 2019 11:04:02 -0700 (PDT) X-Received: by 2002:ae9:e007:: with SMTP id m7mr29616049qkk.87.1567447442347; Mon, 02 Sep 2019 11:04:02 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 2 Sep 2019 20:03:51 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Christian Schneider Cc: Dan Ackroyd , PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Mixed mode methods From: andreas@dqxtech.net (Andreas Hennings) In my experience, things that have different roles or behavior should be differently named. I have seen a lot of functions with dynamic return types based on a mode set in the parameter (e.g. the return type could be string, string[] or string[][] depending on whether some parameter is NULL or not). In all cases, the confusion and ambiguity caused by this was far greater than the supposed / perceived convenience. Often enough, the increased complexity of control flow branches inside the function would lead to bugs, which could remain undiscovered for years. Maybe the only benefits were to not pollute the global namespace as much, and to give access to the same static variables for caching. None of these benefits apply in an object-oriented scenario. A method body which has to handle and distinguish static and non-static calls would easily suffer from the same problems. On Mon, 2 Sep 2019 at 18:03, Christian Schneider wrote: > > Am 02.09.2019 um 17:01 schrieb Dan Ackroyd : > > Also(, without checking to see if it's feasible,) to me a less > > surprising approach would be to allow static and instance methods to > > be declared separately with the same method name. This would at least solve the problem of added complexity in the method body. Still, as Dan Ackroyd points out, there needs to be a clear benefit. > I was considering this approach but that is a special case of Ad hoc polymorphism (https://en.wikipedia.org/wiki/Ad_hoc_polymorphism). > And that's a path I don't want to go down, I don't think that's a good fit for PHP. > It felt more natural to model it similarly to nullable return types. The value of parameter-based polymorphism is for cases where the calling code wants to handle all parameter types in one call, whereas the callee has different implementations for different parameter types. This is not the case here: The calling code does always know whether a call should be static or not, so it can choose the applicable method name. On Mon, 2 Sep 2019 at 18:03, Christian Schneider wrote: > > Am 02.09.2019 um 17:01 schrieb Dan Ackroyd : > > Also(, without checking to see if it's feasible,) to me a less > > surprising approach would be to allow static and instance methods to > > be declared separately with the same method name. > > > > class Foo { > > static function loadXml() { > > echo "I am static method\n"; > > } > > > > function loadXml() { > > echo "I am instance method\n"; > > } > > } > > I was considering this approach but that is a special case of Ad hoc polymorphism (https://en.wikipedia.org/wiki/Ad_hoc_polymorphism). > And that's a path I don't want to go down, I don't think that's a good fit for PHP. > It felt more natural to model it similarly to nullable return types. > > - Chris > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >