|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80858 Undefined behavior when match branch is function returning void
Submitted: 2021-03-13 01:45 UTC Modified: 2021-03-13 01:56 UTC
From: patrick dot kusebauch at gmail dot com Assigned:
Status: Open Package: Documentation problem
PHP Version: 8.0.3 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: patrick dot kusebauch at gmail dot com
New email:
PHP Version: OS:


 [2021-03-13 01:45 UTC] patrick dot kusebauch at gmail dot com
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: 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:

function nothing(): void

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


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:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-13 01:56 UTC]
-Operating System: Any +Operating System:
 [2021-03-13 01:56 UTC]
This is not undefined behaviour because of match, all functions in PHP by default will return NULL even if they are declared void.

This might need to be said in the 'void' type section on the Type Declaration page (

A parse error doesn't make sense as it's at best a compile error (using result of void function), however changing any such behaviour to hard error would require an RFC.
 [2022-12-23 09:03 UTC] amin dot jabari242 at gmail dot com
And today everything is working very well. 
 [2022-12-26 08:08 UTC] ambari242 at gmail dot com
Thanks for sharing that. (
 [2023-03-26 20:29 UTC] myjohnjdf at gmail dot com
The information you have posted is very useful. The sites you have referred was good. Thanks for sharing. (
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Oct 02 19:01:25 2023 UTC