Doc #80858 [NEW]: Undefined behavior when match branch is function returning void

From: Date: Sat, 13 Mar 2021 01:45:12 +0000
Subject: Doc #80858 [NEW]: Undefined behavior when match branch is function returning void
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-18631@lists.php.net to get a copy of this message
From:             patrick dot kusebauch at gmail dot com
Operating system: Any
PHP version:      8.0.3
Package:          Documentation problem
Bug Type:         Documentation Problem
Bug description:Undefined behavior when match branch is function returning void

Description:
------------
In the case that you have a match statement and the expression in one of
the branches is a function that returns void, there is no mention what
is the expected behavior in the documentation. Right now it seems that
it evaluates to NULL. 

This behavior is not well understood as can be seen here:
https://github.com/phpstan/phpstan/issues/4292
and PHPStorm will flag it
as a possible bug: "'void' method result used".

This is not limited to a case where a match statement result is
assigned. All these issues (PHPStorm, PHPStan) are present even if the
match result is not used.

Test script:
---------------
<?php

function nothing(): void
{
 
}

$result = match ('inserted') {
    'inserted' => nothing(),
};

var_dump($result);

Expected result:
----------------
Either parse error on the branch or at least parse error in the
assignment to result would make sense to me.

Actual result:
--------------
NULL

-- 
Edit bug report at https://bugs.php.net/bug.php?id=80858&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=80858&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=80858&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=80858&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=80858&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=80858&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=80858&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=80858&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=80858&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=80858&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=80858&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80858&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=80858&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=80858&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=80858&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=80858&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=80858&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=80858&r=mysqlcfg


Thread (5 messages)

« previous php.doc.bugs (#18631) next »