Commit f14697416e9 for php.net

commit f14697416e98cb2307d9b0839262e5526e189ff2
Author: Tim Düsterhus <tim@tideways-gmbh.com>
Date:   Tue Apr 8 14:23:03 2025 +0200

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

    Co-authored-by: Volker Dusch <volker@tideways-gmbh.com>

diff --git a/Zend/tests/attributes/nodiscard/005.phpt b/Zend/tests/attributes/nodiscard/005.phpt
index ec8f33e5299..9ef15663728 100644
--- a/Zend/tests/attributes/nodiscard/005.phpt
+++ b/Zend/tests/attributes/nodiscard/005.phpt
@@ -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
diff --git a/Zend/tests/attributes/nodiscard/007.phpt b/Zend/tests/attributes/nodiscard/007.phpt
index 84dff0c8e44..1b72de8c22a 100644
--- a/Zend/tests/attributes/nodiscard/007.phpt
+++ b/Zend/tests/attributes/nodiscard/007.phpt
@@ -7,15 +7,11 @@
 --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() -->
diff --git a/Zend/tests/attributes/nodiscard/010.phpt b/Zend/tests/attributes/nodiscard/010.phpt
new file mode 100644
index 00000000000..5534fc3404d
--- /dev/null
+++ b/Zend/tests/attributes/nodiscard/010.phpt
@@ -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
diff --git a/ext/opcache/tests/nodiscard_001.phpt b/ext/opcache/tests/nodiscard_001.phpt
index f4f7b8488e9..7e232f8f44e 100644
--- a/ext/opcache/tests/nodiscard_001.phpt
+++ b/ext/opcache/tests/nodiscard_001.phpt
@@ -7,14 +7,13 @@
 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() {
@@ -28,38 +27,26 @@ function 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)
@@ -71,6 +58,6 @@ function 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
diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php
index b6533d8dc20..e7f4ff88447 100644
--- a/ext/standard/basic_functions.stub.php
+++ b/ext/standard/basic_functions.stub.php
@@ -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 {}

 /**
diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h
index d35377c9007..3d922886431 100644
Binary files a/ext/standard/basic_functions_arginfo.h and b/ext/standard/basic_functions_arginfo.h differ
diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c
index b9190f67530..ba18639aead 100644
--- a/ext/zend_test/test.c
+++ b/ext/zend_test/test.c
@@ -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();
diff --git a/ext/zend_test/test.stub.php b/ext/zend_test/test.stub.php
index 921dadd00ce..10272c51cad 100644
--- a/ext/zend_test/test.stub.php
+++ b/ext/zend_test/test.stub.php
@@ -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")]
diff --git a/ext/zend_test/test_arginfo.h b/ext/zend_test/test_arginfo.h
index 391f2fc500b..62b57223dac 100644
Binary files a/ext/zend_test/test_arginfo.h and b/ext/zend_test/test_arginfo.h differ