[doc-en] master: Fix examples that fail on PHP 8 (#6125)
| From: | Tim Bond via GitHub | Date: | Mon, 23 Nov 2026 08:44:46 +0000 |
| Subject: | [doc-en] master: Fix examples that fail on PHP 8 (#6125) | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-23996@lists.php.net to get a copy of this message | ||
Author: Tim Bond (cookieguru)
Committer: GitHub (web-flow)
Pusher: lacatoire
Date: 2026-11-23T09:44:43+01:00
Commit: https://github.com/php/doc-en/commit/a7de7c1567e76bbced172035485095da9a27bf25
Raw diff: https://github.com/php/doc-en/commit/a7de7c1567e76bbced172035485095da9a27bf25.diff
Fix examples that fail on PHP 8 (#6125)
* Fix the openssl_spki_*() examples that fail on PHP 8
The basic examples for openssl_spki_new(), openssl_spki_export(),
openssl_spki_export_challenge() and openssl_spki_verify() call
openssl_pkey_new('secret password'). The function has only ever taken
an optional array of options, so the string was never valid. It raised
a warning and returned null before PHP 8, and throws a TypeError since,
so the examples stop before reaching the function they document. Call
it without arguments to generate a key with the default options.
* Replace __autoload() in the Phar stub examples
Declaring __autoload() is a fatal error since PHP 8.0. Register the
loader with spl_autoload_register() in the Phar::mapPhar() stub and
in the stubs passed to Phar::setStub() in the Phar::getStub() and
Phar::stopBuffering() examples, as the Phar::startBuffering() example
already does. Escape $class in the double-quoted stubs so it is
written into the stub instead of being interpolated, and update the
documented stub output and its length to match.
Changed paths:
M reference/openssl/functions/openssl-spki-export-challenge.xml
M reference/openssl/functions/openssl-spki-export.xml
M reference/openssl/functions/openssl-spki-new.xml
M reference/openssl/functions/openssl-spki-verify.xml
M reference/phar/Phar/getStub.xml
M reference/phar/Phar/mapPhar.xml
M reference/phar/Phar/stopBuffering.xml
Diff:
diff --git a/reference/openssl/functions/openssl-spki-export-challenge.xml
b/reference/openssl/functions/openssl-spki-export-challenge.xml
index b8c9132e896c..eb3c6387dfdb 100644
--- a/reference/openssl/functions/openssl-spki-export-challenge.xml
+++ b/reference/openssl/functions/openssl-spki-export-challenge.xml
@@ -56,7 +56,7 @@
<programlisting role="php">
<![CDATA[
<?php
-$pkey = openssl_pkey_new('secret password');
+$pkey = openssl_pkey_new();
$spkac = openssl_spki_new($pkey, 'challenge string');
$challenge = openssl_spki_export_challenge(preg_replace('/SPKAC=/', '',
$spkac));
?>
diff --git a/reference/openssl/functions/openssl-spki-export.xml
b/reference/openssl/functions/openssl-spki-export.xml
index ccaaf95413a3..fa6ccae63594 100644
--- a/reference/openssl/functions/openssl-spki-export.xml
+++ b/reference/openssl/functions/openssl-spki-export.xml
@@ -56,7 +56,7 @@
<programlisting role="php">
<![CDATA[
<?php
-$pkey = openssl_pkey_new('secret password');
+$pkey = openssl_pkey_new();
$spkac = openssl_spki_new($pkey, 'challenge string');
$pubKey = openssl_spki_export(preg_replace('/SPKAC=/', '', $spkac));
diff --git a/reference/openssl/functions/openssl-spki-new.xml
b/reference/openssl/functions/openssl-spki-new.xml
index 1804fdd2f9e6..a5673f7c029d 100644
--- a/reference/openssl/functions/openssl-spki-new.xml
+++ b/reference/openssl/functions/openssl-spki-new.xml
@@ -101,7 +101,7 @@
<programlisting role="php">
<![CDATA[
<?php
-$pkey = openssl_pkey_new('secret password');
+$pkey = openssl_pkey_new();
$spkac = openssl_spki_new($pkey, 'testing');
if ($spkac !== NULL) {
diff --git a/reference/openssl/functions/openssl-spki-verify.xml
b/reference/openssl/functions/openssl-spki-verify.xml
index a5b869819f41..cdae84d48e9b 100644
--- a/reference/openssl/functions/openssl-spki-verify.xml
+++ b/reference/openssl/functions/openssl-spki-verify.xml
@@ -56,7 +56,7 @@
<programlisting role="php">
<![CDATA[
<?php
-$pkey = openssl_pkey_new('secret password');
+$pkey = openssl_pkey_new();
$spkac = openssl_spki_new($pkey, 'challenge string');
if (openssl_spki_verify(preg_replace('/SPKAC=/', '', $spkac))) {
diff --git a/reference/phar/Phar/getStub.xml b/reference/phar/Phar/getStub.xml
index d9819b71a693..30eacc6cd13e 100644
--- a/reference/phar/Phar/getStub.xml
+++ b/reference/phar/Phar/getStub.xml
@@ -66,10 +66,9 @@ $p = new Phar('/path/to/my.phar', 0, 'my.phar');
echo $p->getStub();
echo "==NEXT==\n";
$p->setStub("<?php
-function __autoload($class)
-{
- include 'phar://' . str_replace('_', '/', $class);
-}
+spl_autoload_register(function (\$class) {
+ include 'phar://' . str_replace('_', '/', \$class);
+});
Phar::mapPhar('myphar.phar');
include 'phar://myphar.phar/startup.php';
__HALT_COMPILER(); ?>");
@@ -83,10 +82,9 @@ echo $p->getStub();
<?php __HALT_COMPILER(); ?>
==NEXT==
<?php
-function __autoload($class)
-{
+spl_autoload_register(function ($class) {
include 'phar://' . str_replace('_', '/', $class);
-}
+});
Phar::mapPhar('myphar.phar');
include 'phar://myphar.phar/startup.php';
__HALT_COMPILER(); ?>
diff --git a/reference/phar/Phar/mapPhar.xml b/reference/phar/Phar/mapPhar.xml
index c3a690a620a8..287fc1f198be 100644
--- a/reference/phar/Phar/mapPhar.xml
+++ b/reference/phar/Phar/mapPhar.xml
@@ -75,10 +75,9 @@
<programlisting role="php">
<![CDATA[
<?php
-function __autoload($class)
-{
+spl_autoload_register(function ($class) {
include 'phar://me.phar/' . str_replace('_', '/', $class) .
'.php';
-}
+});
try {
Phar::mapPhar('me.phar');
include 'phar://me.phar/startup.php';
diff --git a/reference/phar/Phar/stopBuffering.xml b/reference/phar/Phar/stopBuffering.xml
index bdd3dbc126dc..23646652f239 100644
--- a/reference/phar/Phar/stopBuffering.xml
+++ b/reference/phar/Phar/stopBuffering.xml
@@ -73,10 +73,9 @@ $p['file1.txt'] = 'hi';
$p->startBuffering();
var_dump($p->getStub());
$p->setStub("<?php
-function __autoload(\$class)
-{
+spl_autoload_register(function (\$class) {
include 'phar://brandnewphar.phar/' . str_replace('_', '/',
\$class) . '.php';
-}
+});
Phar::mapPhar('brandnewphar.phar');
include 'phar://brandnewphar.phar/startup.php';
__HALT_COMPILER();");
@@ -89,11 +88,10 @@ var_dump($p->getStub());
<screen>
<![CDATA[
string(24) "<?php __HALT_COMPILER();"
-string(195) "<?php
-function __autoload($class)
-{
+string(209) "<?php
+spl_autoload_register(function ($class) {
include 'phar://' . str_replace('_', '/', $class);
-}
+});
Phar::mapPhar('brandnewphar.phar');
include 'phar://brandnewphar.phar/startup.php';
__HALT_COMPILER();"