Skip to content

Commit b7b1f53

Browse files
committed
ext/standard: Remove #[\NoDiscard] from flock()
1 parent 8c266e8 commit b7b1f53

File tree

9 files changed

+70
-66
lines changed

9 files changed

+70
-66
lines changed
+1-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
--TEST--
2-
#[\NoDiscard]: Native function and method.
2+
#[\NoDiscard]: Native method.
33
--FILE--
44
<?php
55

6-
$f = tmpfile();
7-
flock($f, LOCK_SH | LOCK_NB);
8-
fclose($f);
9-
106
$date = new DateTimeImmutable('now');
117
$date->setTimestamp(0);
128

139
?>
1410
--EXPECTF--
15-
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
16-
1711
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

Zend/tests/attributes/nodiscard/007.phpt

+3-7
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@ zend_test.observer.execute_internal=1
77
--FILE--
88
<?php
99

10-
$f = tmpfile();
11-
flock($f, LOCK_SH | LOCK_NB);
12-
fclose($f);
10+
zend_test_nodiscard();
1311

1412
?>
1513
--EXPECTF--
16-
<!-- internal enter tmpfile() -->
1714
<!-- internal enter NoDiscard::__construct() -->
1815

19-
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
20-
<!-- internal enter flock() -->
21-
<!-- internal enter fclose() -->
16+
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
17+
<!-- internal enter zend_test_nodiscard() -->
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
#[\NoDiscard]: Native function.
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
8+
zend_test_nodiscard();
9+
10+
?>
11+
--EXPECTF--
12+
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

ext/opcache/tests/nodiscard_001.phpt

+22-36
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ opcache
1010
--FILE--
1111
<?php
1212

13-
$f = tmpfile();
14-
flock($f, LOCK_SH | LOCK_NB);
15-
(void)flock($f, LOCK_SH | LOCK_NB);
16-
$success = flock($f, LOCK_SH | LOCK_NB);
17-
fclose($f);
13+
zend_test_nodiscard();
14+
(void)zend_test_nodiscard();
15+
$success = zend_test_nodiscard();
1816

1917
#[\NoDiscard]
2018
function test() {
@@ -28,38 +26,26 @@ $obj = test();
2826
?>
2927
--EXPECTF--
3028
$_main:
31-
; (lines=29, args=0, vars=3, tmps=%d)
29+
; (lines=17, args=0, vars=2, tmps=%d)
3230
; (after optimizer)
3331
; %s
34-
0000 INIT_FCALL 0 %d string("tmpfile")
35-
0001 V3 = DO_ICALL
36-
0002 ASSIGN CV0($f) V3
37-
0003 INIT_FCALL 2 %d string("flock")
38-
0004 SEND_VAR CV0($f) 1
39-
0005 SEND_VAL int(5) 2
40-
0006 DO_FCALL_BY_NAME
41-
0007 INIT_FCALL 2 %d string("flock")
42-
0008 SEND_VAR CV0($f) 1
43-
0009 SEND_VAL int(5) 2
44-
0010 V3 = DO_ICALL
45-
0011 FREE V3
46-
0012 INIT_FCALL 2 %d string("flock")
47-
0013 SEND_VAR CV0($f) 1
48-
0014 SEND_VAL int(5) 2
49-
0015 V3 = DO_ICALL
50-
0016 ASSIGN CV1($success) V3
51-
0017 INIT_FCALL 1 %d string("fclose")
52-
0018 SEND_VAR CV0($f) 1
53-
0019 DO_ICALL
54-
0020 INIT_FCALL 0 %d string("test")
55-
0021 DO_FCALL_BY_NAME
56-
0022 INIT_FCALL 0 %d string("test")
57-
0023 V3 = DO_UCALL
58-
0024 FREE V3
59-
0025 INIT_FCALL 0 %d string("test")
60-
0026 V3 = DO_UCALL
61-
0027 ASSIGN CV2($obj) V3
62-
0028 RETURN int(1)
32+
0000 INIT_FCALL 0 %d string("zend_test_nodiscard")
33+
0001 DO_FCALL_BY_NAME
34+
0002 INIT_FCALL 0 %d string("zend_test_nodiscard")
35+
0003 V2 = DO_ICALL
36+
0004 FREE V2
37+
0005 INIT_FCALL 0 %d string("zend_test_nodiscard")
38+
0006 V2 = DO_ICALL
39+
0007 ASSIGN CV0($success) V2
40+
0008 INIT_FCALL 0 %d string("test")
41+
0009 DO_FCALL_BY_NAME
42+
0010 INIT_FCALL 0 %d string("test")
43+
0011 V2 = DO_UCALL
44+
0012 FREE V2
45+
0013 INIT_FCALL 0 %d string("test")
46+
0014 V2 = DO_UCALL
47+
0015 ASSIGN CV1($obj) V2
48+
0016 RETURN int(1)
6349

6450
test:
6551
; (lines=3, args=0, vars=0, tmps=%d)
@@ -71,6 +57,6 @@ test:
7157
LIVE RANGES:
7258
0: 0001 - 0002 (new)
7359

74-
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
60+
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
7561

7662
Warning: The return value of function test() should either be used or intentionally ignored by casting it as (void) in %s on line %d

ext/standard/basic_functions.stub.php

-1
Original file line numberDiff line numberDiff line change
@@ -2732,7 +2732,6 @@ function proc_nice(int $priority): bool {}
27322732
* @param resource $stream
27332733
* @param int $would_block
27342734
*/
2735-
#[\NoDiscard(message: "as locking the stream might have failed")]
27362735
function flock($stream, int $operation, &$would_block = null): bool {}
27372736

27382737
/**

ext/standard/basic_functions_arginfo.h

+2-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/zend_test/test.c

+7
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ static ZEND_FUNCTION(zend_test_deprecated_attr)
124124
ZEND_PARSE_PARAMETERS_NONE();
125125
}
126126

127+
static ZEND_FUNCTION(zend_test_nodiscard)
128+
{
129+
ZEND_PARSE_PARAMETERS_NONE();
130+
131+
RETURN_LONG(1);
132+
}
133+
127134
static ZEND_FUNCTION(zend_test_deprecated_nodiscard)
128135
{
129136
ZEND_PARSE_PARAMETERS_NONE();

ext/zend_test/test.stub.php

+2
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ function zend_test_deprecated(mixed $arg = null): void {}
218218
#[\Deprecated(message: "custom message")]
219219
function zend_test_deprecated_attr(): void {}
220220

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

222224
#[\Deprecated(message: "custom message")]
223225
#[\NoDiscard(message: "custom message 2")]

ext/zend_test/test_arginfo.h

+21-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)