回答編集履歴
2
edit
test
CHANGED
@@ -57,3 +57,77 @@
|
|
57
57
|
}
|
58
58
|
|
59
59
|
```
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
簡易実装イメージ
|
64
|
+
|
65
|
+
```php
|
66
|
+
|
67
|
+
<?php
|
68
|
+
|
69
|
+
<?php
|
70
|
+
|
71
|
+
class p {
|
72
|
+
|
73
|
+
protected $con;
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
protected function execute(){
|
78
|
+
|
79
|
+
echo $this->con;
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
class c1 extends p{
|
88
|
+
|
89
|
+
function __construct(){
|
90
|
+
|
91
|
+
$this->con = "aa";
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
function ex(){
|
96
|
+
|
97
|
+
$this->execute();
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
class c2 extends p{
|
104
|
+
|
105
|
+
function __construct(){
|
106
|
+
|
107
|
+
$this->con = "bb";
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
function ex(){
|
112
|
+
|
113
|
+
$this->execute();
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
$c1 = new c1();
|
122
|
+
|
123
|
+
$c2 = new c2();
|
124
|
+
|
125
|
+
$c1->ex();
|
126
|
+
|
127
|
+
$c2->ex();
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
```
|
1
edit
test
CHANGED
@@ -9,3 +9,51 @@
|
|
9
9
|
|
10
10
|
|
11
11
|
親側は引数に$sql(おそらくstring)をとり、戻り値にarrayが指定されるにも関わらず、子側は引数も戻り値もありません。
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
とりあえず動かすなら子のほうをこう
|
16
|
+
|
17
|
+
```php
|
18
|
+
|
19
|
+
public function select($sql){
|
20
|
+
|
21
|
+
return parent::select($sql);
|
22
|
+
|
23
|
+
}
|
24
|
+
|
25
|
+
```
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
ですが、今回のようなミスを防ぐためにも引数、戻り値に[型宣言](https://www.php.net/manual/ja/language.types.declarations.php)することを強くすすめます。
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
```php
|
34
|
+
|
35
|
+
//親
|
36
|
+
|
37
|
+
public function select(string $sql):array{
|
38
|
+
|
39
|
+
$hoge=$this->pdo();
|
40
|
+
|
41
|
+
$stmt=$hoge->query($sql);
|
42
|
+
|
43
|
+
$items=$stmt->fetchAll(PDO::FETCH_ASSOC);
|
44
|
+
|
45
|
+
return $items;
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
//子
|
52
|
+
|
53
|
+
public function select(string $sql):array{
|
54
|
+
|
55
|
+
return parent::select($sql);
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
```
|