回答編集履歴

1

加筆修正

2018/04/30 03:22

投稿

退会済みユーザー
test CHANGED
@@ -41,3 +41,83 @@
41
41
 
42
42
 
43
43
  ![実行結果](cd459388fd8b195b75b27900eaaec990.png)
44
+
45
+
46
+
47
+ test::method_x()を2度呼び出すとfatal errorになるということで、
48
+
49
+ こういうコードを書いて検証してみました。
50
+
51
+
52
+
53
+ ```php
54
+
55
+ <?php
56
+
57
+
58
+
59
+ class test{
60
+
61
+ public function method_x(){
62
+
63
+ function method_y(){
64
+
65
+ echo __FUNCTION__ . "\n";
66
+
67
+ echo __METHOD__. "\n";
68
+
69
+ }
70
+
71
+ echo __FUNCTION__ . "\n";
72
+
73
+ echo __METHOD__. "\n";
74
+
75
+ method_y();
76
+
77
+ }
78
+
79
+ public function method_z() {
80
+
81
+ method_y();
82
+
83
+ return true;
84
+
85
+ }
86
+
87
+ }
88
+
89
+ $obj = new test();
90
+
91
+ $obj->method_x();
92
+
93
+ $obj->method_z();
94
+
95
+ ```
96
+
97
+
98
+
99
+ ![実行結果2](73559db5f034dc239a300cc972f33210.png)
100
+
101
+
102
+
103
+ このとき、
104
+
105
+ ```php
106
+
107
+ $obj = new test();
108
+
109
+ ///$obj->method_x();
110
+
111
+ $obj->method_z();
112
+
113
+ ```
114
+
115
+
116
+
117
+ とするとこれもFatal error: Uncaught Error: Call to undefined function method_y() なので、
118
+
119
+ test::method_x() を呼ばないと存在しない test::method_y() であり、
120
+
121
+ class test内に存在し続け、
122
+
123
+ class testの外からは呼べないから、(プライベート関数は不適切で)クラス内メンバー関数とでも言うべきなのでしょうか。