Skip to content

Commit d6f5401

Browse files
committed
Fixed examples, and made some self-contained
1 parent 5003a6e commit d6f5401

File tree

20 files changed

+100
-37
lines changed

20 files changed

+100
-37
lines changed

language/oop5/anonymous.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,8 @@ class@anonymous/in/oNi1A0x7f8636ad2021
185185
<programlisting role="php">
186186
<![CDATA[
187187
<?php
188-
189188
// Using an anonymous class
190-
$util->setLogger(new readonly class('[DEBUG]') {
189+
var_dump(new readonly class('[DEBUG]') {
191190
public function __construct(private string $prefix)
192191
{
193192
}

language/oop5/basic.xml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,16 @@ readonly class Foo
224224
<programlisting role="php">
225225
<![CDATA[
226226
<?php
227+
class SimpleClass {
228+
}
229+
227230
$instance = new SimpleClass();
231+
var_dump($instance);
228232
229233
// This can also be done with a variable:
230234
$className = 'SimpleClass';
231235
$instance = new $className(); // new SimpleClass()
236+
var_dump($instance);
232237
?>
233238
]]>
234239
</programlisting>
@@ -296,6 +301,9 @@ object(ClassD)#1 (0) {
296301
<programlisting role="php">
297302
<![CDATA[
298303
<?php
304+
class SimpleClass {
305+
public string $var;
306+
}
299307
300308
$instance = new SimpleClass();
301309
@@ -375,16 +383,18 @@ bool(true)
375383
<programlisting role="php">
376384
<![CDATA[
377385
<?php
378-
echo (new DateTime())->format('Y');
386+
echo (new DateTime())->format('Y'), PHP_EOL;
387+
379388
// surrounding parentheses are optional as of PHP 8.4.0
380-
echo new DateTime()->format('Y');
389+
echo new DateTime()->format('Y'), PHP_EOL;
381390
?>
382391
]]>
383392
</programlisting>
384393
&example.outputs.similar;
385394
<screen>
386395
<![CDATA[
387-
2016
396+
2025
397+
2025
388398
]]>
389399
</screen>
390400
</example>
@@ -498,6 +508,14 @@ echo ($obj->bar)(), PHP_EOL;
498508
<programlisting role="php">
499509
<![CDATA[
500510
<?php
511+
class SimpleClass
512+
{
513+
function displayVar()
514+
{
515+
echo "Parent class\n";
516+
}
517+
}
518+
501519
class ExtendClass extends SimpleClass
502520
{
503521
// Redefine the parent method
@@ -757,9 +775,10 @@ Does\Not\Exist
757775
namespace NS {
758776
class ClassName {
759777
}
778+
779+
$c = new ClassName();
780+
print $c::class;
760781
}
761-
$c = new ClassName();
762-
print $c::class;
763782
?>
764783
]]>
765784
</programlisting>

language/oop5/decon.xml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ function test(
236236
<programlisting role="php">
237237
<![CDATA[
238238
<?php
239+
$some_json_string = '{ "id": 1004, "name": "Elephpant" }';
240+
$some_xml_string = "<animal><id>1005</id><name>Elephpant</name></animal>";
241+
239242
class Product {
240243
241244
private ?int $id;
@@ -256,19 +259,20 @@ class Product {
256259
return new static($data['id'], $data['name']);
257260
}
258261
259-
public static function fromXml(string $xml): static {
260-
// Custom logic here.
261-
$data = convert_xml_to_array($xml);
262+
public static function fromXml(string $xml): static {a
263+
$data = simplexml_load_string($xml);
262264
$new = new static();
263-
$new->id = $data['id'];
264-
$new->name = $data['name'];
265+
$new->id = $data->id;
266+
$new->name = $data->name;
265267
return $new;
266268
}
267269
}
268270
269271
$p1 = Product::fromBasicData(5, 'Widget');
270272
$p2 = Product::fromJson($some_json_string);
271273
$p3 = Product::fromXml($some_xml_string);
274+
275+
var_dump($p1, $p2, $p3);
272276
]]>
273277
</programlisting>
274278
</example>

language/oop5/overloading.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,6 @@ class PropertyTest
186186
}
187187
188188
189-
echo "<pre>\n";
190-
191189
$obj = new PropertyTest;
192190
193191
$obj->a = 1;

language/oop5/paamayim-nekudotayim.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ echo MyClass::CONST_VALUE;
6161
<programlisting role="php">
6262
<![CDATA[
6363
<?php
64+
class MyClass {
65+
const CONST_VALUE = 'A constant value';
66+
}
67+
6468
class OtherClass extends MyClass
6569
{
6670
public static $my_static = 'static var';

language/oop5/property-hooks.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ class Example
220220
</simpara>
221221
<programlisting role="php">
222222
<![CDATA[
223+
<?php
223224
class Example
224225
{
225226
public function __construct(
@@ -241,6 +242,7 @@ class Example
241242
</simpara>
242243
<programlisting role="php">
243244
<![CDATA[
245+
<?php
244246
class Example
245247
{
246248
public private(set) DateTimeInterface $created {

reference/dom/domattr/construct.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<![CDATA[
5353
<?php
5454
55-
$dom = new DOMDocument('1.0', 'iso-8859-1');
55+
$dom = new DOMDocument('1.0', 'utf-8');
5656
$element = $dom->appendChild(new DOMElement('root'));
5757
$attr = $element->setAttributeNode(new DOMAttr('attr', 'attrvalue'));
5858
echo $dom->saveXML();
@@ -64,7 +64,7 @@ echo $dom->saveXML();
6464
<screen>
6565
<![CDATA[
6666
<?xml version="1.0" encoding="utf-8"?>
67-
<root attr="attrvalue" />
67+
<root attr="attrvalue"/>
6868
]]>
6969
</screen>
7070
</example>

reference/dom/domdocument/replacechildren.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
$doc = new DOMDocument;
3535
$doc->loadXML("<container><hello/></container>");
3636
37-
$doc->replaceWith("beautiful", $doc->createElement("world"));
37+
$doc->replaceChildren("beautiful", $doc->createElement("world"));
3838
3939
echo $doc->saveXML();
4040
?>

reference/dom/domdocumentfragment/replacechildren.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ $doc->loadXML("<container><hello/></container>");
3636
$fragment = $doc->createDocumentFragment();
3737
$fragment->append("hello");
3838
39-
$fragment->replaceWith("beautiful", $doc->createElement("world"));
39+
$fragment->replaceChildren("beautiful", $doc->createElement("world"));
4040
4141
echo $doc->saveXML($fragment);
4242
?>

reference/libxml/functions/libxml-set-streams-context.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ $context = stream_context_create($opts);
9494
libxml_set_streams_context($context);
9595
9696
// request a file through HTTP
97-
$doc = DOMDocument::load('http://www.example.com/file.xml');
98-
97+
$dom = new DOMDocument;
98+
$doc = $dom->load('http://www.example.com/file.xml');
9999
?>
100100
]]>
101101
</programlisting>

0 commit comments

Comments
 (0)