回答編集履歴
1
補足追加
test
CHANGED
@@ -41,3 +41,109 @@
|
|
41
41
|
|
42
42
|
|
43
43
|
で取得はできると思います。
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
もうちょっと補足しておくと、
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
```php
|
52
|
+
|
53
|
+
class Sample
|
54
|
+
|
55
|
+
{
|
56
|
+
|
57
|
+
public $a = 1;
|
58
|
+
|
59
|
+
protected $b = 2;
|
60
|
+
|
61
|
+
private $c = 3;
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
public function change()
|
66
|
+
|
67
|
+
{
|
68
|
+
|
69
|
+
$this->a = 11;
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
public function getB()
|
76
|
+
|
77
|
+
{
|
78
|
+
|
79
|
+
return $this->b;
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
public function getC()
|
86
|
+
|
87
|
+
{
|
88
|
+
|
89
|
+
return $this->c;
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
class Sample2 extends Sample
|
98
|
+
|
99
|
+
{
|
100
|
+
|
101
|
+
public function getB()
|
102
|
+
|
103
|
+
{
|
104
|
+
|
105
|
+
return $this->b;
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
public function getC()
|
112
|
+
|
113
|
+
{
|
114
|
+
|
115
|
+
return $this->c;
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
$sample = new Sample();
|
124
|
+
|
125
|
+
echo $sample->a // 1が出力される
|
126
|
+
|
127
|
+
$sample->change();
|
128
|
+
|
129
|
+
echo $sample->a // 11が出力される
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
echo $sample->b // $bのアクセス修飾子はprotectedなのでアクセスできない
|
134
|
+
|
135
|
+
echo $sample->getB(); // 2 クラス内ではbを見ることが出来るので、それを返すので値が取れる
|
136
|
+
|
137
|
+
echo $sample->c // 基本的に$bと一緒です。
|
138
|
+
|
139
|
+
echo $sample->getC(); // 3
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
$sample2 = new Sample2();
|
144
|
+
|
145
|
+
echo $sample2->getB(); // 2
|
146
|
+
|
147
|
+
echo $sample2->getC(); // privateは継承先からは見れませんのでエラーになります。
|
148
|
+
|
149
|
+
```
|