Skip to content

Commit 6e70c51

Browse files
authored
[Sync EN] WASM: enable runnable examples for language sections (#5456) (#2804)
* [Sync EN] WASM: enable runnable examples for language sections (#5456) * Set Maintainer to lacatoire in language sections
1 parent 5734d8a commit 6e70c51

3 files changed

Lines changed: 37 additions & 44 deletions

File tree

language/constants.xml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- $Revision$ -->
3-
<!-- EN-Revision: f4f96ef8b2a95283c92ea2183fe1dedf06f3ad22 Maintainer: yannick Status: ready -->
3+
<!-- EN-Revision: 6e885e52412ad979aa5fbb620bb84e886fc0ebe8 Maintainer: lacatoire Status: ready -->
44
<!-- Reviewed: no -->
55
<!-- CREDITS: DAnnebicque -->
6-
<chapter xml:id="language.constants" xmlns="http://docbook.org/ns/docbook">
6+
<chapter xml:id="language.constants" xmlns="http://docbook.org/ns/docbook" annotations="interactive">
77
<title>Les constantes</title>
88
<simpara>
99
Une constante est un identifiant (un nom) qui représente une valeur
@@ -39,7 +39,7 @@
3939
<para>
4040
<example>
4141
<title>Noms valides et invalides pour les constantes</title>
42-
<programlisting role="php">
42+
<programlisting role="php" annotations="non-interactive">
4343
<![CDATA[
4444
<?php
4545
// Noms valides
@@ -54,8 +54,6 @@ define("2FOO", "something");
5454
// PHP peut un jour fournir une constante magique nommée
5555
// ainsi, ce qui va corrompre vos scripts.
5656
define("__FOO__", "something");
57-
58-
?>
5957
]]>
6058
</programlisting>
6159
</example>
@@ -186,7 +184,6 @@ define("__FOO__", "something");
186184
echo CONSTANT; // affiche "Bonjour le monde."
187185
echo Constant; // Lève une Error : Undefined constant "Constant"
188186
// Avant PHP 8.0.0, affiche "Constant" et émet un avertissement.
189-
?>
190187
]]>
191188
</programlisting>
192189
</example>
@@ -201,23 +198,22 @@ define("__FOO__", "something");
201198
// Simple valeur scalaire
202199
const CONSTANT = 'Bonjour le monde !';
203200
204-
echo CONSTANT;
201+
echo CONSTANT . "\n";
205202
206203
// Expression scalaire
207-
const ANOTHER_CONST = CONSTANT.'; Au revoir le monde !';
208-
echo ANOTHER_CONST;
204+
const ANOTHER_CONST = CONSTANT . '; Au revoir le monde !';
205+
echo ANOTHER_CONST . "\n";
209206
210207
const ANIMALS = array('chien', 'chat', 'oiseaux');
211-
echo ANIMALS[1]; // affiche "chat"
208+
echo ANIMALS[1] . "\n"; // affiche "chat"
212209
213210
// Tableaux constants
214-
define('ANIMALS', array(
211+
define('ANIMALS_DEF', array(
215212
'chien',
216213
'chat',
217214
'oiseaux'
218215
));
219-
echo ANIMALS[1]; // affiche "chat"
220-
?>
216+
echo ANIMALS_DEF[1] . "\n"; // affiche "chat"
221217
]]>
222218
</programlisting>
223219
</example>

language/exceptions.xml

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<!-- EN-Revision: c81a48e58fc530a74827316027fae74668d17a1d Maintainer: yannick Status: ready -->
2+
<!-- EN-Revision: 6e885e52412ad979aa5fbb620bb84e886fc0ebe8 Maintainer: lacatoire Status: ready -->
33
<!-- Reviewed: no -->
44

5-
<chapter xml:id="language.exceptions" xmlns="http://docbook.org/ns/docbook">
5+
<chapter xml:id="language.exceptions" xmlns="http://docbook.org/ns/docbook" annotations="interactive">
66
<title>Les exceptions</title>
7+
<note>
8+
<simpara>Voir aussi la classe <exceptionname>Exception</exceptionname></simpara>
9+
</note>
710
<para>
811
PHP a une gestion des exceptions similaire à ce qu'offrent les autres
912
langages de programmation.
@@ -124,15 +127,14 @@
124127
</para>
125128
<example>
126129
<title>Convertir l'error reporting en exceptions</title>
127-
<programlisting role="php">
130+
<programlisting role="php" annotations="non-interactive">
128131
<![CDATA[
129132
<?php
130133
function exceptions_error_handler($severity, $message, $filename, $lineno) {
131134
throw new ErrorException($message, 0, $severity, $filename, $lineno);
132135
}
133136
134137
set_error_handler('exceptions_error_handler');
135-
?>
136138
]]>
137139
</programlisting>
138140
</example>
@@ -169,7 +171,6 @@ try {
169171
170172
// On continue l'exécution
171173
echo "Bonjour le monde !\n";
172-
?>
173174
]]>
174175
</programlisting>
175176
&example.outputs;
@@ -211,7 +212,6 @@ try {
211212
212213
// On continue l'exécution
213214
echo "Bonjour le monde !\n";
214-
?>
215215
]]>
216216
</programlisting>
217217
&example.outputs;
@@ -242,7 +242,6 @@ function test() {
242242
}
243243
244244
echo test();
245-
?>
246245
]]>
247246
</programlisting>
248247
&example.outputs;
@@ -277,8 +276,6 @@ class Test {
277276
278277
$foo = new Test;
279278
$foo->testing();
280-
281-
?>
282279
]]>
283280
</programlisting>
284281
&example.outputs;
@@ -310,8 +307,6 @@ class Test {
310307
311308
$foo = new Test;
312309
$foo->testing();
313-
314-
?>
315310
]]>
316311
</programlisting>
317312
&example.outputs;
@@ -339,7 +334,6 @@ try {
339334
} catch (SpecificException) {
340335
print "Une SpecificException a été levée, mais les détails ne nous intéressent pas.";
341336
}
342-
?>
343337
]]>
344338
</programlisting>
345339
&example.outputs;
@@ -369,7 +363,6 @@ try {
369363
} catch (Exception $e) {
370364
print $e->getMessage();
371365
}
372-
?>
373366
]]>
374367
</programlisting>
375368
&example.outputs;
@@ -417,13 +410,13 @@ string(6) "Fourth"
417410
<title>Étendre les Exceptions</title>
418411
<para>
419412
Une classe d'exception définie par l'utilisateur peut être définie en étendant
420-
la classe Exception intégrée. Les membres et les propriétés ci-dessous montrent
413+
la classe <exceptionname>Exception</exceptionname> intégrée. Les membres et les propriétés ci-dessous montrent
421414
ce qui est accessible dans la classe enfant qui dérive de la classe Exception
422415
intégrée.
423416
</para>
424417
<example>
425418
<title>La classe d'exception intégrée</title>
426-
<programlisting role="php">
419+
<programlisting role="php" annotations="non-interactive">
427420
<![CDATA[
428421
<?php
429422
class Exception implements Throwable
@@ -451,12 +444,11 @@ class Exception implements Throwable
451444
// Peut être redéfinie
452445
public function __toString(); // chaîne formatée pour l'affichage
453446
}
454-
?>
455447
]]>
456448
</programlisting>
457449
</example>
458450
<para>
459-
Si une classe étend la classe Exception intégrée et redéfinit le <link
451+
Si une classe étend la classe <exceptionname>Exception</exceptionname> intégrée et redéfinit le <link
460452
linkend="language.oop5.decon">constructeur</link>, il est fortement recommandé
461453
qu'elle appelle également <link
462454
linkend="language.oop5.paamayim-nekudotayim">parent::__construct()</link>
@@ -534,7 +526,7 @@ class TestException
534526
}
535527
536528
537-
// Exemple 1
529+
echo "# Exemple 1\n";
538530
try {
539531
$o = new TestException(TestException::THROW_CUSTOM);
540532
} catch (MyException $e) { // Sera capturée
@@ -546,10 +538,9 @@ try {
546538
547539
// Poursuite de l'exécution
548540
var_dump($o); // Null
549-
echo "\n\n";
550541
551542
552-
// Exemple 2
543+
echo "\n\n# Exemple 2\n";
553544
try {
554545
$o = new TestException(TestException::THROW_DEFAULT);
555546
} catch (MyException $e) { // Ne correspond pas à ce type
@@ -561,10 +552,9 @@ try {
561552
562553
// Poursuite de l'exécution
563554
var_dump($o); // Null
564-
echo "\n\n";
565555
566556
567-
// Exemple 3
557+
echo "\n\n# Exemple 3\n";
568558
try {
569559
$o = new TestException(TestException::THROW_CUSTOM);
570560
} catch (Exception $e) { // Sera capturée
@@ -573,10 +563,9 @@ try {
573563
574564
// Poursuite de l'exécution
575565
var_dump($o); // Null
576-
echo "\n\n";
577566
578567
579-
// Exemple 4
568+
echo "\n\n# Exemple 4\n";
580569
try {
581570
$o = new TestException();
582571
} catch (Exception $e) { // Sauté, aucune exception
@@ -585,8 +574,6 @@ try {
585574
586575
// Poursuite de l'exécution
587576
var_dump($o); // TestException
588-
echo "\n\n";
589-
?>
590577
]]>
591578
</programlisting>
592579
</example>

language/expressions.xml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<!-- EN-Revision: f4f96ef8b2a95283c92ea2183fe1dedf06f3ad22 Maintainer: yannick Status: ready -->
2+
<!-- EN-Revision: 6e885e52412ad979aa5fbb620bb84e886fc0ebe8 Maintainer: lacatoire Status: ready -->
33
<!-- Reviewed: no -->
4-
<chapter xml:id="language.expressions" xmlns="http://docbook.org/ns/docbook">
4+
<chapter xml:id="language.expressions" xmlns="http://docbook.org/ns/docbook" annotations="interactive">
55
<title>Les expressions</title>
66
<simpara>
77
Les expressions sont les pièces de construction les plus importantes de PHP.
@@ -26,7 +26,7 @@
2626
Un exemple plus complexe concerne les fonctions. Par exemple,
2727
considérons la fonction suivante :
2828
<informalexample>
29-
<programlisting role="php">
29+
<programlisting role="php" annotations="non-interactive">
3030
<![CDATA[
3131
<?php
3232
function foo ()
@@ -151,7 +151,7 @@ function foo ()
151151
</para>
152152
<para>
153153
<informalexample>
154-
<programlisting role="php">
154+
<programlisting role="php" annotations="non-interactive">
155155
<![CDATA[
156156
<?php
157157
$first ? $second : $third
@@ -179,22 +179,32 @@ $first ? $second : $third
179179
<?php
180180
function double($i)
181181
{
182-
return $i*2;
182+
return $i * 2;
183183
}
184184
185185
$b = $a = 5; /* Assigne la valeur 5 aux variables $a et $b */
186186
$c = $a++; /* Post-incrémentation de la variable $a et assignation de
187187
la valeur à la variable $c */
188+
print "a = {$a}; b = {$b}; c = {$c}" . PHP_EOL;
189+
188190
$e = $d = ++$b; /* Pre-incrémentation, et assignation de la valeur aux
189191
variables $d et $e */
192+
print "b = {$b}; d = {$d}; e = {$e}" . PHP_EOL;
193+
190194
/* à ce niveau, les variables $d et $e sont égales à 6 */
195+
191196
$f = double($d++); /* assignation du double de la valeur de $d à la variable $f ($f vaut 12),
192197
puis incrémentation de la valeur de $d */
198+
print "d = {$d}; f = {$f}" . PHP_EOL;
199+
193200
$g = double(++$e); /* assigne deux fois la valeur de $e après
194201
incrémentation, 2*7 = 14 à $g */
202+
print "e = {$e}; g = {$g}" . PHP_EOL;
203+
195204
$h = $g += 10; /* Tout d'abord, $g est incrémentée de 10, et donc $g vaut 24.
196205
Ensuite, la valeur de $g, (24) est assignée à la variable $h,
197206
qui vaut donc elle aussi 24. */
207+
print "g = {$g}; h = {$h}" . PHP_EOL;
198208
?>
199209
]]>
200210
</programlisting>

0 commit comments

Comments
 (0)