パーフェクトPHPの第7章で、オートロードに関する処理をまとめたクラスである、「ClassLoader」クラスのコードで分からない部分があったのですが、PHPマニュアルを見ても良く分からなかった為、ご質問させて頂きました。
php
1 2<?php 3class ClassLoader 4{ 5 protected $dirs; 6 public function register() 7 { 8 spl_autoload_register(array($this,'loadClass')); 9 10 } 11 public function registerDir($dir) 12 { 13 $this->dir[] = $dir; 14 15 } 16 17 public function loadClass($class) 18 { 19 foreach($this->dirs as $dir){ 20 $file = $dir . '/' . $class . '.php'; 21 if(is_readable($file)){ 22 require $file; 23 return; 24 } 25 } 26 } 27}
上記の
php
1spl_autoload_register(array($this,'loadClass'))
ここの部分なのですが、spl_autoload_registerの引数は何を指しているのでしょうか?
「$this」と「loadClass」の2つの値を配列として扱っていますが、配列にしなければならない理由があるのでしょうか?
また「$this」は何を示しているのでしょうか?
ご助言頂けましたら幸いです。
よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー