[doc-en] master: Fix examples that emit deprecation notices on PHP 8.x (#6150)
| From: | Tim Bond via GitHub | Date: | Wed, 25 Nov 2026 05:56:51 +0000 |
| Subject: | [doc-en] master: Fix examples that emit deprecation notices on PHP 8.x (#6150) | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-24017@lists.php.net to get a copy of this message | ||
Author: Tim Bond (cookieguru)
Committer: GitHub (web-flow)
Pusher: lacatoire
Date: 2026-11-25T06:56:47+01:00
Commit: https://github.com/php/doc-en/commit/4ffb5959dfd98113b38b5342ce35e9068f494a19
Raw diff: https://github.com/php/doc-en/commit/4ffb5959dfd98113b38b5342ce35e9068f494a19.diff
Fix examples that emit deprecation notices on PHP 8.x (#6150)
* Use an explicit nullable type in the allowsNull() example
Implicitly nullable parameter types, such as stdClass $param2 = null,
are deprecated since PHP 8.4.0, so the example emitted a deprecation
notice. Declare the parameter as ?stdClass. The documented output is
unchanged.
* Allow the dynamic property in the hasDefaultValue() example
Creating a dynamic property is deprecated since PHP 8.2.0 unless the
class has the #[AllowDynamicProperties] attribute. The example creates
one on purpose to show a property without a default value, so add the
attribute. Before PHP 8.0.0 it is read as a comment.
* Add the types to the SplObjectStorage::getHash() example
Overriding getHash() without a compatible return type is deprecated
since PHP 8.1.0, so the example emitted a deprecation notice. Use the
types from the method signature, getHash(object $object): string.
* Pass the escape parameter in the SplFileObject::fputcsv() example
Omitting the escape parameter is deprecated since PHP 8.4.0, because
its default value will change. Pass an empty string, as the fputcsv()
example does. The data contains no backslashes, so the output is the
same.
Changed paths:
M reference/reflection/reflectionproperty/hasdefaultvalue.xml
M reference/reflection/reflectiontype/allowsnull.xml
M reference/spl/splfileobject/fputcsv.xml
M reference/spl/splobjectstorage/gethash.xml
Diff:
diff --git a/reference/reflection/reflectionproperty/hasdefaultvalue.xml
b/reference/reflection/reflectionproperty/hasdefaultvalue.xml
index 10d2aed9f1f5..f352359f405b 100644
--- a/reference/reflection/reflectionproperty/hasdefaultvalue.xml
+++ b/reference/reflection/reflectionproperty/hasdefaultvalue.xml
@@ -40,6 +40,7 @@
<programlisting role="php">
<![CDATA[
<?php
+#[AllowDynamicProperties]
class Foo {
public $bar;
public ?int $baz;
diff --git a/reference/reflection/reflectiontype/allowsnull.xml
b/reference/reflection/reflectiontype/allowsnull.xml
index 4dc36f065201..840433fce13a 100644
--- a/reference/reflection/reflectiontype/allowsnull.xml
+++ b/reference/reflection/reflectiontype/allowsnull.xml
@@ -37,7 +37,7 @@
<programlisting role="php">
<![CDATA[
<?php
-function someFunction(string $param, stdClass $param2 = null) {}
+function someFunction(string $param, ?stdClass $param2 = null) {}
$reflectionFunc = new ReflectionFunction('someFunction');
$reflectionParams = $reflectionFunc->getParameters();
diff --git a/reference/spl/splfileobject/fputcsv.xml b/reference/spl/splfileobject/fputcsv.xml
index 020976c41d4b..cbe328b9beab 100644
--- a/reference/spl/splfileobject/fputcsv.xml
+++ b/reference/spl/splfileobject/fputcsv.xml
@@ -126,7 +126,7 @@ $list = array (
$file = new SplFileObject('file.csv', 'w');
foreach ($list as $fields) {
- $file->fputcsv($fields);
+ $file->fputcsv($fields, ',', '"', '');
}
?>
diff --git a/reference/spl/splobjectstorage/gethash.xml b/reference/spl/splobjectstorage/gethash.xml
index 2f709fc82471..1b84f1876688 100644
--- a/reference/spl/splobjectstorage/gethash.xml
+++ b/reference/spl/splobjectstorage/gethash.xml
@@ -69,8 +69,8 @@
<![CDATA[
<?php
class OneSpecimenPerClassStorage extends SplObjectStorage {
- public function getHash($o) {
- return get_class($o);
+ public function getHash(object $object): string {
+ return get_class($object);
}
}
class A {}