[doc-en] master: fix: use strict comparsions of returns in openssl_verify examples (#4827)
| From: | Josh via GitHub | Date: | Tue, 01 Sep 2026 11:52:10 +0000 |
| Subject: | [doc-en] master: fix: use strict comparsions of returns in openssl_verify examples (#4827) | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-23683@lists.php.net to get a copy of this message | ||
Author: Josh (joshtrichards)
Committer: GitHub (web-flow)
Pusher: lacatoire
Date: 2026-09-01T13:52:07+02:00
Commit: https://github.com/php/doc-en/commit/9e5f75b8c1d87da6ee825ae7d1b2a3da218b5c69
Raw diff: https://github.com/php/doc-en/commit/9e5f75b8c1d87da6ee825ae7d1b2a3da218b5c69.diff
fix: use strict comparsions of returns in openssl_verify examples (#4827)
* fix: use strict comparsions of returns in openssl_verify examples
Fixes #4574 for openssl_verify
* openssl: warn that the verify functions return truthy on error
Comparing the result of openssl_verify(), openssl_x509_verify(),
openssl_pkcs7_verify() and openssl_x509_checkpurpose() with a plain truth
test treats an error as a successful verification, since both the success
value and -1 are truthy. Also use a strict comparison in the remaining
example.
* ldap, zip: warn that these functions return truthy on error
ldap_compare() and ZipArchive::getArchiveFlag() share the shape of the
openssl verify functions: the success value and -1 are both truthy, so a
plain truth test treats an error as a positive result. ldap_compare()
matters most, its own example being a password check.
---------
Co-authored-by: Louis-Arnaud <la.catoire@gmail.com>
Changed paths:
M reference/ldap/functions/ldap-compare.xml
M reference/openssl/functions/openssl-pkcs7-verify.xml
M reference/openssl/functions/openssl-verify.xml
M reference/openssl/functions/openssl-x509-checkpurpose.xml
M reference/openssl/functions/openssl-x509-verify.xml
M reference/zip/ziparchive/getarchiveflag.xml
Diff:
diff --git a/reference/ldap/functions/ldap-compare.xml b/reference/ldap/functions/ldap-compare.xml
index 61f062d6ae87..37f11397d1ed 100644
--- a/reference/ldap/functions/ldap-compare.xml
+++ b/reference/ldap/functions/ldap-compare.xml
@@ -76,6 +76,14 @@
Returns &true; if <parameter>value</parameter> matches otherwise returns
&false;. Returns -1 on error.
</para>
+ <warning>
+ <simpara>
+ Both &true; and <literal>-1</literal> are
+ <link linkend="language.types.boolean.casting">truthy</link>, so a plain
+ truth test such as <code>if (ldap_compare(...))</code> treats an error as a
+ match. The result must be compared strictly against &true;.
+ </simpara>
+ </warning>
</refsect1>
<refsect1 role="changelog">
diff --git a/reference/openssl/functions/openssl-pkcs7-verify.xml
b/reference/openssl/functions/openssl-pkcs7-verify.xml
index 13f4a2056938..e31d0356b49e 100644
--- a/reference/openssl/functions/openssl-pkcs7-verify.xml
+++ b/reference/openssl/functions/openssl-pkcs7-verify.xml
@@ -105,6 +105,15 @@
(the message has been tampered with, or the signing certificate is invalid),
or -1 on error.
</para>
+ <warning>
+ <simpara>
+ Both &true; and <literal>-1</literal> are
+ <link linkend="language.types.boolean.casting">truthy</link>, so a plain
+ truth test such as <code>if (openssl_pkcs7_verify(...))</code> treats an error as a
+ successful verification. The result must be compared strictly against
+ &true;.
+ </simpara>
+ </warning>
</refsect1>
<refsect1 role="changelog">
diff --git a/reference/openssl/functions/openssl-verify.xml
b/reference/openssl/functions/openssl-verify.xml
index be2b62745bd8..787c4f8922ab 100644
--- a/reference/openssl/functions/openssl-verify.xml
+++ b/reference/openssl/functions/openssl-verify.xml
@@ -88,6 +88,15 @@ MIIBCgK...</literal>)
Returns 1 if the signature is correct, 0 if it is incorrect, and
-1 or &false; on error.
</para>
+ <warning>
+ <simpara>
+ Both the success value and the error value are
+ <link linkend="language.types.boolean.casting">truthy</link>, so a plain
+ truth test such as <code>if (openssl_verify(...))</code> treats an error as a
+ successful verification. The result must be compared strictly against
+ <literal>1</literal>.
+ </simpara>
+ </warning>
</refsect1>
<refsect1 role="changelog">
@@ -136,9 +145,9 @@ $pubkeyid =
openssl_pkey_get_public("file://src/openssl-0.9.6/demos/sign/cert.pe
// state whether signature is okay or not
$ok = openssl_verify($data, $signature, $pubkeyid);
-if ($ok == 1) {
+if ($ok === 1) {
echo "good";
-} elseif ($ok == 0) {
+} elseif ($ok === 0) {
echo "bad";
} else {
echo "ugly, error checking signature";
@@ -170,9 +179,9 @@ openssl_sign($data, $signature, $private_key_res,
"sha256WithRSAEncryption");
//verify signature
$ok = openssl_verify($data, $signature, $public_key_res, OPENSSL_ALGO_SHA256);
-if ($ok == 1) {
+if ($ok === 1) {
echo "valid";
-} elseif ($ok == 0) {
+} elseif ($ok === 0) {
echo "invalid";
} else {
echo "error: ".openssl_error_string();
diff --git a/reference/openssl/functions/openssl-x509-checkpurpose.xml
b/reference/openssl/functions/openssl-x509-checkpurpose.xml
index 81f9b71bd0a3..17bdd4f6f4c7 100644
--- a/reference/openssl/functions/openssl-x509-checkpurpose.xml
+++ b/reference/openssl/functions/openssl-x509-checkpurpose.xml
@@ -115,6 +115,15 @@
Returns &true; if the certificate can be used for the intended purpose,
&false; if it cannot, or -1 on error.
</para>
+ <warning>
+ <simpara>
+ Both &true; and <literal>-1</literal> are
+ <link linkend="language.types.boolean.casting">truthy</link>, so a plain
+ truth test such as <code>if (openssl_x509_checkpurpose(...))</code> treats an error
as a
+ successful verification. The result must be compared strictly against
+ &true;.
+ </simpara>
+ </warning>
</refsect1>
<refsect1 role="changelog">
diff --git a/reference/openssl/functions/openssl-x509-verify.xml
b/reference/openssl/functions/openssl-x509-verify.xml
index cc084e6a7e4f..5394c7170f31 100644
--- a/reference/openssl/functions/openssl-x509-verify.xml
+++ b/reference/openssl/functions/openssl-x509-verify.xml
@@ -47,6 +47,15 @@ MIIBCgK...</literal>)
Returns 1 if the signature is correct, 0 if it is incorrect, and
-1 on error.
</para>
+ <warning>
+ <simpara>
+ Both the success value and the error value are
+ <link linkend="language.types.boolean.casting">truthy</link>, so a plain
+ truth test such as <code>if (openssl_x509_verify(...))</code> treats an error as a
+ successful verification. The result must be compared strictly against
+ <literal>1</literal>.
+ </simpara>
+ </warning>
</refsect1>
<refsect1 role="changelog">
@@ -110,8 +119,8 @@
foreach($cont["options"]["ssl"]["peer_certificate_chain"] as
$chaincert)
{
$chainparsed = openssl_x509_parse($chaincert);
$chain_public_key = openssl_get_publickey($chaincert);
- $r = openssl_x509_verify($x509, $chain_public_key);
- if ($r==1)
+ $r = openssl_x509_verify($x509, $chain_public_key);
+ if ($r === 1)
{
echo $certparsed['subject']['CN'];
echo " was digitally signed by ";
diff --git a/reference/zip/ziparchive/getarchiveflag.xml
b/reference/zip/ziparchive/getarchiveflag.xml
index 0376832b45b9..17bb576be1e4 100644
--- a/reference/zip/ziparchive/getarchiveflag.xml
+++ b/reference/zip/ziparchive/getarchiveflag.xml
@@ -69,6 +69,14 @@
<simpara>
Returns 1 if flag is set for archive, 0 if not, and -1 if an error occurred.
</simpara>
+ <warning>
+ <simpara>
+ Both <literal>1</literal> and <literal>-1</literal> are
+ <link linkend="language.types.boolean.casting">truthy</link>, so a plain
+ truth test treats an error as the flag being set. The result must be
+ compared strictly against <literal>1</literal>.
+ </simpara>
+ </warning>
</refsect1>
<refsect1 role="examples">