Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108761 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 39445 invoked from network); 25 Feb 2020 22:06:11 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Feb 2020 22:06:11 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D4E931804E4 for ; Tue, 25 Feb 2020 12:23:40 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 25 Feb 2020 12:23:40 -0800 (PST) Received: by mail-lf1-f43.google.com with SMTP id n25so202179lfl.0 for ; Tue, 25 Feb 2020 12:23:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=qquJnZVoo6a+XyN4inwbq4HNRqbBPiWIGaE6+Khth4E=; b=F8N6RzbXywgn7agygXGI5/OrccvQW8sFOsnXrRsTSO6hBO3y6as8AeHL38C7OnPaXu uCWhKiBoydkVHcW1oi6KXWtw5dUPH6J1lbseLiB7Q5Q7f+qyOzEg0ZmLOc8Yibf2sCZA SjqqhzDtUa/sUzR14yYxALwcMFscvpVPceg6kl09UZ70e6lLFsNAkmN0BQhLD1o2cef4 6CNy7LM6GAlgsrDMZ3RZXimKkb4s1+ljOuv1Qz0KvmMChqr3E4moW+oV/LHJW/z3jOp1 8MXfE7OTnsnHGk7yL1yFKcbp3E64HWJHLVGp8jWMQQhzf3xBolznGAcBcFXD1JLjsPB1 AyOA== 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=qquJnZVoo6a+XyN4inwbq4HNRqbBPiWIGaE6+Khth4E=; b=GArjD+1UeW9xyFQCzVCIsYS9qd/b3A7oWBFL0tso5Zymc9Zy7/LtuFO1g1MLMjfUDA FJ8dOLQ284pO0tsGJzeay72bbxPLW8cE539+b2ztfiX3Cvp7iNgdY3/lpod7+eR0BIXc jPLOGzjyKJCyf0sGv0V5UiEByalnM+VeCUe/qpSOyp4pLELtTs5hCZwlI0nWR3QRNO5I mjJ6oRIXhrd7wXEYoHnMVaLjIQ7EHtI/UkDekQASx+0mkFPtAbLF2H28P2mQaJiXcULT Xha3WHJwlkAatQxO95V9xsqOBn1hUyKU/hXHZxfwd0RdrE7zHNiQ3usSA6JfakKIFkq+ bOwQ== X-Gm-Message-State: APjAAAVw+2fTJUYz9Y3+YM2nXg8/NjzqPBd4WCfTn/2T9ATeErHlrut+ m/mlU+crOJ3eiVUWXdC7r7zikbv9MwceXSJv5lagxsUU X-Google-Smtp-Source: APXvYqyu5/Anv1vjfT7Q0hUxfSfNvD/vQ5uO4Y4g9z13iik5kSEZPVyKuG7As0+EEA2s4hQlPGYR6P5vB3T6c3Z2AyY= X-Received: by 2002:ac2:5046:: with SMTP id a6mr306970lfm.191.1582662218867; Tue, 25 Feb 2020 12:23:38 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 25 Feb 2020 21:23:22 +0100 Message-ID: To: Bishop Bettini Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000005ae9c1059f6c4331" Subject: Re: [PHP-DEV] Deprecate ReflectionParameter::isArray() and friends From: nikita.ppv@gmail.com (Nikita Popov) --0000000000005ae9c1059f6c4331 Content-Type: text/plain; charset="UTF-8" On Tue, Feb 25, 2020 at 8:12 PM Bishop Bettini wrote: > On Tue, Feb 25, 2020 at 10:33 AM Nikita Popov > wrote: > >> I've put up https://github.com/php/php-src/pull/5209 to deprecate the >> following reflection methods: >> >> * ReflectionParameter::isArray() >> * ReflectionParameter::isCallable() >> * ReflectionParameter::getClass() >> >> These APIs have been superseded by ReflectionParameter::getType() since >> PHP >> 7.0. Types introduced since that time are not available through the old >> APIs. The behavior of these methods becomes increasingly confusing with >> additional type system extensions. With the addition of union types in PHP >> 8: >> >> * isArray() will return true if the type is array or ?array, but not any >> other union type. >> * getClass() will return a ReflectionClass for T|int etc, as long as the >> union only contains a single type. T1|T2 will return null. >> >> There is really no reasonable behavior for these methods in the presence >> of >> union types; we should start phasing them out. >> >> One point I'm not sure about is whether we want to deprecate >> ReflectionParameter::allowsNull() as well. Logically this method belongs >> on >> ReflectionType (and does in fact exist there), but the way it is >> formulated >> is still compatible with union types, so leaving it alone is a >> possibility. >> > > Why do you say there's no "reasonable behavior ... in the presence of > union types"? To me, the following seem like reasonable interpretations in > a post-union-type world: > > ::isArray() returns true IIF is_array(type) === true for at least one type > in the parameter > ::isCallable() returns true IIF is_callable(type) === true for at least > one type in the parameter > ::getClass() returns null IIF class_exists(type) === false for all types > in the parameter; returns ReflectionClass IIF class_exists(type) for > exactly one type in the parameter; throws \TypeError otherwise > I don't think those behaviors correspond to the spirit or practical usage of these methods. I would expect that existing code calling isArray() will only work correctly if it really is an isolated array type (or, for historical reasons, a nullable array type, which was not considered a separate "type" at the time). This is pretty useless speculation though, and I'm honestly not sure what you are trying to tell me with your email. Sure, it's possible to come up with a behavior for them (and in fact, they already have one, which I described before), but that doesn't change the fact that at this time, this is a quite incomplete API (doesn't even support scalar types), and we should encourage people to migrate to the more complete ReflectionType based API. No...? Regards, Nikita --0000000000005ae9c1059f6c4331--