11<?xml version =" 1.0" encoding =" utf-8" ?>
2- <!-- EN-Revision: 376d3f9c2ef7fcd64d8b8503d552013acefb8b5b Maintainer: sobak Status: ready -->
2+ <!-- EN-Revision: c1f37a6c270aadbbb3da56a3973ffd62197adf2b Maintainer: sobak Status: ready -->
33 <sect1 xml : id =" language.oop5.decon" xmlns =" http://docbook.org/ns/docbook" >
44 <title >Konstruktory i destruktory</title >
55
@@ -194,7 +194,7 @@ class Punkt {
194194 </note >
195195 <example >
196196 <title >Użycie new w inicjalizatorach</title >
197- <programlisting role =" php" >
197+ <programlisting role =" php" annotations = " non-interactive " >
198198<![CDATA[
199199<?php
200200
@@ -237,6 +237,9 @@ function test(
237237 <programlisting role =" php" >
238238<![CDATA[
239239<?php
240+ $jakis_string_json = '{ "id": 1004, "name": "Elephpant" }';
241+ $jakis_string_xml = "<animal><id>1005</id><name>Elephpant</name></animal>";
242+
240243class Produkt {
241244
242245 private ?int $id;
@@ -258,18 +261,19 @@ class Produkt {
258261 }
259262
260263 public static function fromXml(string $xml): static {
261- // Dowolna własna logika.
262- $data = convert_xml_to_array($xml);
264+ $data = simplexml_load_string($xml);
263265 $new = new static();
264- $new->id = $data['id'] ;
265- $new->nazwa = $data[' nazwa'] ;
266+ $new->id = $data->id ;
267+ $new->nazwa = $data-> nazwa;
266268 return $new;
267269 }
268270}
269271
270272$p1 = Produkt::fromBasicData(5, 'Nazwa produktu');
271273$p2 = Produkt::fromJson($jakis_string_json);
272274$p3 = Produkt::fromXml($jakis_string_xml);
275+
276+ var_dump($p1, $p2, $p3);
273277]]>
274278 </programlisting >
275279 </example >
0 commit comments