Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ext/standard: Remove #[\NoDiscard] from flock() #18255

Merged
merged 1 commit into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions Zend/tests/attributes/nodiscard/005.phpt
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
--TEST--
#[\NoDiscard]: Native function and method.
#[\NoDiscard]: Native method.
--FILE--
<?php

$f = tmpfile();
flock($f, LOCK_SH | LOCK_NB);
fclose($f);

$date = new DateTimeImmutable('now');
$date->setTimestamp(0);

?>
--EXPECTF--
Warning: The return value of function flock() should either be used or intentionally ignored by casting it as (void), as locking the stream might have failed in %s on line %d

Warning: The return value of method DateTimeImmutable::setTimestamp() should either be used or intentionally ignored by casting it as (void), as DateTimeImmutable::setTimestamp() does not modify the object itself in %s on line %d
10 changes: 3 additions & 7 deletions Zend/tests/attributes/nodiscard/007.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ zend_test.observer.execute_internal=1
--FILE--
<?php

$f = tmpfile();
flock($f, LOCK_SH | LOCK_NB);
fclose($f);
zend_test_nodiscard();

?>
--EXPECTF--
<!-- internal enter tmpfile() -->
<!-- internal enter NoDiscard::__construct() -->

Warning: The return value of function flock() should either be used or intentionally ignored by casting it as (void), as locking the stream might have failed in %s on line %d
<!-- internal enter flock() -->
<!-- internal enter fclose() -->
Warning: The return value of function zend_test_nodiscard() should either be used or intentionally ignored by casting it as (void), custom message in %s on line %d
<!-- internal enter zend_test_nodiscard() -->
12 changes: 12 additions & 0 deletions Zend/tests/attributes/nodiscard/010.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
#[\NoDiscard]: Native function.
--EXTENSIONS--
zend_test
--FILE--
<?php

zend_test_nodiscard();

?>
--EXPECTF--
Warning: The return value of function zend_test_nodiscard() should either be used or intentionally ignored by casting it as (void), custom message in %s on line %d
59 changes: 23 additions & 36 deletions ext/opcache/tests/nodiscard_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ opcache.optimization_level=-1
opcache.opt_debug_level=0x20000
--EXTENSIONS--
opcache
zend_test
--FILE--
<?php

$f = tmpfile();
flock($f, LOCK_SH | LOCK_NB);
(void)flock($f, LOCK_SH | LOCK_NB);
$success = flock($f, LOCK_SH | LOCK_NB);
fclose($f);
zend_test_nodiscard();
(void)zend_test_nodiscard();
$success = zend_test_nodiscard();

#[\NoDiscard]
function test() {
Expand All @@ -28,38 +27,26 @@ $obj = test();
?>
--EXPECTF--
$_main:
; (lines=29, args=0, vars=3, tmps=%d)
; (lines=17, args=0, vars=2, tmps=%d)
; (after optimizer)
; %s
0000 INIT_FCALL 0 %d string("tmpfile")
0001 V3 = DO_ICALL
0002 ASSIGN CV0($f) V3
0003 INIT_FCALL 2 %d string("flock")
0004 SEND_VAR CV0($f) 1
0005 SEND_VAL int(5) 2
0006 DO_FCALL_BY_NAME
0007 INIT_FCALL 2 %d string("flock")
0008 SEND_VAR CV0($f) 1
0009 SEND_VAL int(5) 2
0010 V3 = DO_ICALL
0011 FREE V3
0012 INIT_FCALL 2 %d string("flock")
0013 SEND_VAR CV0($f) 1
0014 SEND_VAL int(5) 2
0015 V3 = DO_ICALL
0016 ASSIGN CV1($success) V3
0017 INIT_FCALL 1 %d string("fclose")
0018 SEND_VAR CV0($f) 1
0019 DO_ICALL
0020 INIT_FCALL 0 %d string("test")
0021 DO_FCALL_BY_NAME
0022 INIT_FCALL 0 %d string("test")
0023 V3 = DO_UCALL
0024 FREE V3
0025 INIT_FCALL 0 %d string("test")
0026 V3 = DO_UCALL
0027 ASSIGN CV2($obj) V3
0028 RETURN int(1)
0000 INIT_FCALL 0 %d string("zend_test_nodiscard")
0001 DO_FCALL_BY_NAME
0002 INIT_FCALL 0 %d string("zend_test_nodiscard")
0003 V2 = DO_ICALL
0004 FREE V2
0005 INIT_FCALL 0 %d string("zend_test_nodiscard")
0006 V2 = DO_ICALL
0007 ASSIGN CV0($success) V2
0008 INIT_FCALL 0 %d string("test")
0009 DO_FCALL_BY_NAME
0010 INIT_FCALL 0 %d string("test")
0011 V2 = DO_UCALL
0012 FREE V2
0013 INIT_FCALL 0 %d string("test")
0014 V2 = DO_UCALL
0015 ASSIGN CV1($obj) V2
0016 RETURN int(1)

test:
; (lines=3, args=0, vars=0, tmps=%d)
Expand All @@ -71,6 +58,6 @@ test:
LIVE RANGES:
0: 0001 - 0002 (new)

Warning: The return value of function flock() should either be used or intentionally ignored by casting it as (void), as locking the stream might have failed in %s on line %d
Warning: The return value of function zend_test_nodiscard() should either be used or intentionally ignored by casting it as (void), custom message in %s on line %d

Warning: The return value of function test() should either be used or intentionally ignored by casting it as (void) in %s on line %d
1 change: 0 additions & 1 deletion ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2732,7 +2732,6 @@ function proc_nice(int $priority): bool {}
* @param resource $stream
* @param int $would_block
*/
#[\NoDiscard(message: "as locking the stream might have failed")]
function flock($stream, int $operation, &$would_block = null): bool {}

/**
Expand Down
13 changes: 2 additions & 11 deletions ext/standard/basic_functions_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions ext/zend_test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ static ZEND_FUNCTION(zend_test_deprecated_attr)
ZEND_PARSE_PARAMETERS_NONE();
}

static ZEND_FUNCTION(zend_test_nodiscard)
{
ZEND_PARSE_PARAMETERS_NONE();

RETURN_LONG(1);
}

static ZEND_FUNCTION(zend_test_deprecated_nodiscard)
{
ZEND_PARSE_PARAMETERS_NONE();
Expand Down
2 changes: 2 additions & 0 deletions ext/zend_test/test.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ function zend_test_deprecated(mixed $arg = null): void {}
#[\Deprecated(message: "custom message")]
function zend_test_deprecated_attr(): void {}

#[\NoDiscard(message: "custom message")]
function zend_test_nodiscard(): int {}

#[\Deprecated(message: "custom message")]
#[\NoDiscard(message: "custom message 2")]
Expand Down
25 changes: 21 additions & 4 deletions ext/zend_test/test_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading