PHPのCLASSについて質問です。
例)ディレクトリを作成する場合
php
1class bbb 2{ 3 public function __construct() 4 {} 5 public function createDir($new_dir) 6 { 7 remove_files($new_dir); 8 mkdir($new_dir, 0777, true); 9 } 10} 11 12class aaa 13{ 14 protected $ccc; 15 public function __construct() 16 { 17 $ccc = new bbb(); 18 // $this->ccc = new bbb(); にしないとダメ? 19 } 20 public function run($new_dir) 21 { 22 // ここがNULLになる 23 $this->ccc->createDir($new_dir); 24 } 25} 26 27$new_dir = /path/; 28$ddd = new aaa(); 29$ddd->run($new_dir);
コメント部分に記載しているのですが、
上記の場合「$ccc = new bbb();」を「$this->ccc」で取得できないのでしょうか?
NULLなので指定方法が間違っているのかとおもいまして質問させていただきました。
よろしくお願いします。
PHP ver > 7
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/21 05:40