-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathobject.xml
More file actions
110 lines (96 loc) · 2.6 KB
/
object.xml
File metadata and controls
110 lines (96 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: e587d0655e426f97b3fcb431453da5030e743b23 Maintainer: yannick Status: ready -->
<!-- Reviewed: yes -->
<sect1 xml:id="language.types.object">
<title>Les objets</title>
<sect2 xml:id="language.types.object.init">
<title>Initialisation des objets</title>
<para>
Pour créer un nouvel <type>object</type>, utiliser le mot clé <literal>new</literal>
afin d'instancier une classe :
</para>
<example>
<title>Construction d'objet</title>
<programlisting role="php">
<![CDATA[
<?php
class foo
{
function do_foo()
{
echo "Doing foo.";
}
}
$bar = new foo;
$bar->do_foo();
?>
]]>
</programlisting>
</example>
<simpara>
Pour une discussion complète, voir le chapitre sur
<link linkend="language.oop5">les classes et les objets</link>.
</simpara>
</sect2>
<sect2 xml:id="language.types.object.casting">
<title>Conversion en un objet</title>
<para>
Si un objet est converti en un objet, il ne sera pas modifié.
Si une valeur de n'importe quel type est convertie en un objet,
une nouvelle instance de la classe interne <classname>stdClass</classname>
sera créée. Si la valeur est &null;, la nouvelle instance sera vide.
Un <type>array</type> se convertit en <type>object</type> avec les propriétés
nommées au regard des clés avec leurs valeurs correspondantes. Il est à noter que
dans ce cas, avant PHP 7.2.0 les clés numériques ont été inaccessibles à
moins d'être itérées.
</para>
<example>
<title>Conversion en un objet</title>
<programlisting role="php">
<![CDATA[
<?php
$obj = (object) array('1' => 'foo');
var_dump(isset($obj->{'1'})); // affiche 'bool(true)'
// Déprécié depuis PHP 8.1
var_dump(key($obj)); // affiche 'string(1) "1"'
?>
]]>
</programlisting>
</example>
<para>
Pour toute autre valeur, un membre appelé <literal>scalar</literal>
contiendra la valeur.
</para>
<example>
<title>Conversion <literal>(object)</literal></title>
<programlisting role="php">
<![CDATA[
<?php
$obj = (object) 'ciao';
echo $obj->scalar; // Affiche : 'ciao'
?>
]]>
</programlisting>
</example>
</sect2>
</sect1>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->