Skip to content

#[NoDiscard] and (void) - some errors cannot be ignored #18301

Closed
@DanielEScherzer

Description

@DanielEScherzer

Description

The following code:

<?php

$count = 0;

#[NoDiscard]
function incCount() {
	global $count;
	$count++;
	return $count;
}

for ( $count = 0; $count < 3; incCount() ) {
	echo $count . "\n";
}

Resulted in this output:

0

Warning: The return value of function incCount() should either be used or intentionally ignored by casting it as (void) in /in/rnVPV on line 12
1

Warning: The return value of function incCount() should either be used or intentionally ignored by casting it as (void) in /in/rnVPV on line 12
2

Warning: The return value of function incCount() should either be used or intentionally ignored by casting it as (void) in /in/rnVPV on line 12

But when I added void:

Parse error: syntax error, unexpected token "(void)", expecting ")" in /in/TQrqs on line 12

Process exited with code 255.

PHP Version

PHP master

Operating System

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions