メソッドの中にメソッド入れられないけど、
プライベート関数なら入れられます。
php
1<?php
2
3class test{
4 public function method_x(){
5 function method_y(){
6 echo __FUNCTION__ . "\n";
7 echo __METHOD__. "\n";
8 }
9 echo __FUNCTION__ . "\n";
10 echo __METHOD__. "\n";
11 method_y();
12 }
13}
14$obj = new test();
15$obj->method_x();
test::method_x()を2度呼び出すとfatal errorになるということで、
こういうコードを書いて検証してみました。
php
1<?php
2
3class test{
4 public function method_x(){
5 function method_y(){
6 echo __FUNCTION__ . "\n";
7 echo __METHOD__. "\n";
8 }
9 echo __FUNCTION__ . "\n";
10 echo __METHOD__. "\n";
11 method_y();
12 }
13 public function method_z() {
14 method_y();
15 return true;
16 }
17}
18$obj = new test();
19$obj->method_x();
20$obj->method_z();
このとき、
php
1$obj = new test();
2///$obj->method_x();
3$obj->method_z();
とするとこれもFatal error: Uncaught Error: Call to undefined function method_y() なので、
test::method_x() を呼ばないと存在しない test::method_y() であり、
class test内に存在し続け、
class testの外からは呼べないから、(プライベート関数は不適切で)クラス内メンバー関数とでも言うべきなのでしょうか。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/04/13 09:48
退会済みユーザー
2018/04/13 09:49
2018/04/13 10:22
退会済みユーザー
2018/04/13 11:21
2018/04/13 11:25
退会済みユーザー
2018/04/13 11:29
2018/04/29 10:50
退会済みユーザー
2018/04/30 03:24
退会済みユーザー
2018/04/30 03:47
退会済みユーザー
2018/04/30 13:39