Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108758 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 23847 invoked from network); 25 Feb 2020 20:55:26 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Feb 2020 20:55:26 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 555FD1804FD for ; Tue, 25 Feb 2020 11:12:53 -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=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, 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-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (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 11:12:52 -0800 (PST) Received: by mail-qk1-f172.google.com with SMTP id j8so226441qka.11 for ; Tue, 25 Feb 2020 11:12:52 -0800 (PST) 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:reply-to :from:date:message-id:subject:to:cc; bh=QvePCHL6oRkBmrAPPpX2yYpi/eZLuzkJ1SET14o4Utc=; b=pN8EOcluW6aleqd7uFsRgI+N46edvajf0SHsw0PMOw9vYpmOVFiuARtLVw/rxKjmxD 3Ucw4Hd9C0OxsFpOxjUmp0q2jHWfHMLvpzz3W5H+520kWvsyrfbQxJI0Aj1XJcx5EXEF 6ACtJzMzyqyMTK6XOQGlX9lk9acWd53hza/CF73dDz8oaExgRUo8+2fI3bkNLA1XWPDe 0E97+8HgX5GL+LVXzbz8AYrF8Y0PWxCtSQASnzNP2xYzEhHuISulhG0ubOuAFGN6PZ6k AM2W42R7eAt/zi+CKdHcbqp/DJPgFk21/t1iVr+NToiN7vdMcDPsFFsBVMbOt794j4CH RHWg== X-Gm-Message-State: APjAAAWXIqcNSvPE35werV5Y2PX91FHw+p5jNaUuijWmxUnge413vQnf myvuTTGEgn7nP/Vf+1k36SAU1Y+rDG3nx4RYZz8= X-Google-Smtp-Source: APXvYqw9+tTZqLjhS9jqtOnFQAup7FvbfWE0gdJxaWUINKmBNBY6nnIprDczqT0La58e/1TOtGSBp0GxB1lkpBAn8/c= X-Received: by 2002:a05:620a:14ac:: with SMTP id x12mr403709qkj.83.1582657971392; Tue, 25 Feb 2020 11:12:51 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Reply-To: bishop@php.net Date: Tue, 25 Feb 2020 14:12:15 -0500 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000002f95a3059f6b468c" Subject: Re: [PHP-DEV] Deprecate ReflectionParameter::isArray() and friends From: bishop@php.net (Bishop Bettini) --0000000000002f95a3059f6b468c Content-Type: text/plain; charset="UTF-8" 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 --0000000000002f95a3059f6b468c--