Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129974 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id BF5FD1A00BC for ; Mon, 2 Feb 2026 03:46:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1770004000; bh=vdJ0FocNytOnh9YyEviOKRSPFLc2TX6YvVK+mVQDtZ0=; h=Date:Subject:To:References:From:In-Reply-To:From; b=F/3nM2ouq/yV7TF0W0rxS9VI23E0w0lWawMJQurryu+vZckMUAQujRLPMpi2v/MpZ cpbTkY/R9NP9wQUvrP3RA9Ow2ZRMOZYUe2EPuQ+v7Xy5OcvftcX5Yvh3KLL/0knVPh IeUWca3lM76r27ttK8xGzNwZ1KQN8d6YeEJFI75TN9r9BwXmdUgkKlTFpXuuJQZLcJ uFj2iZt0U85vMViAGNXFjhsdNHuJtIdOyvjro+zN/hSZTv+NtODFnvu1XSD8C7D0VI B0lM2PYcO21RIcWattNueN0LN986P8unnYI2T83GHKUw2RPSkfC80dBt+ePXGUmRCh 5u1K5KPQxhDKA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CD07B180047 for ; Mon, 2 Feb 2026 03:46:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,DMARC_MISSING, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from chuck.smtp.mailx.hosts.net.nz (chuck.smtp.mailx.hosts.net.nz [43.245.52.157]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 2 Feb 2026 03:46:36 +0000 (UTC) Received: from 122-57-27-239-adsl.sparkbb.co.nz ([122.57.27.239] helo=[192.168.1.67]) by chuck.smtp.mailx.hosts.net.nz with esmtpsa authed as varteg.nz (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_128_GCM:128) (Exim 4.96) (envelope-from ) id 1vmktP-007qMr-2V for internals@lists.php.net; Mon, 02 Feb 2026 16:46:27 +1300 Message-ID: <78e9c0ed-8c30-499f-8597-7352f6fb8d51@varteg.nz> Date: Mon, 2 Feb 2026 16:46:21 +1300 Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] Return expression To: internals@lists.php.net References: Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Hosts-DKIM-Check: none From: Weedpacket@varteg.nz (Morgan) On 2026-02-02 13:18, Rob Landers wrote: > > > > From an observability point of view, you lost me when you said return's > type is "never". > > https://3v4l.org/plpIf#v8.5.0 > > We can clearly see the type is "null", unless you mean something more > abstract? > I'm referring to the expression's value as it may exist in a larger expression, primarily for type checking. To use the match{} example, what value does $split get when $len == 1, because in that case the statement boils down to "$split = return false;"? Evaluation never comes back to the assignment to assign $split anything, in the same way that a call to a function of type never shouldn't see evaluation coming back to the call site. If $split were something still visible after function return ("$o->p"), since the assignment didn't happen it would still have its previous value. But as I alluded and you noted, this wouldn't be observable: the caller gets the value of the return expression's operand (or null, if no such operand was provided, in which case why are you trying to see the value of a function of type void?) If you were doing static analysis, making the type of a return expression that of its operand could be an issue: in that match{} example there is no assertion that $split is supposed to contain a boolean. Let's say it's supposed to be an int. "int|bool" would be an incorrect inference; since never is a bottom type and thus a subtype of every type, "int|never" == "int". On the other hand, "int|Exception" is just as invalid, but throwing exceptions from inside expressions is pretty well-behaved; I think modelling return's semantics the same way would work, but I don't know enough of the internals to make that judgement. Basically, the type of a return expression would be the type of a throw.