=======================================================
<?php
class FileFinder {
private $onFound; //
หมายถึงอะไร private function __construct(
$path, $onFound, $maxDepth) {
//$ เหมือนมัน วนๆ คือค่าอะไร เคยเขียนแต่ $path = brabra ;// ค่า $path, $onFound, $maxDepth คืออะไร เอามาจากใหน $this->onFound =
$onFound; $this->iterate(
$path, $maxDepth);
}
private function iterate(
$path, $maxDepth) {
$d = opendir(
$path);
while ($e = readdir($d)) {
if (
$e == '.' || $e == '..') { continue; }
$absPath = "
$path/$e";
if (is_dir($absPath)) {
if ($maxDepth != 0) {
$this->iterate($absPath, $maxDepth - 1);
}
} else {
call_user_func_array($this->onFound, array($absPath));
}
}
closedir($d);
}
public static function find(
$path, $onFound, $maxDepth = 0) {
return new self(
$path, $onFound, $maxDepth);
}
}
$count = $bytes = 0;
FileFinder::find('.', function($file) use (&$count, &$bytes) {
++$count;
$bytes += filesize($file);
}, 1);
echo "Nr files: $count; bytes used: $bytes\n";
===================================================
สีแดงๆ มันมายังไง การใช้งาน ใช้ยังไงส่วนใหญ่จะศึกษาOOPแบบหาโค๊ดมาแกะเอา มันก็ใช้งานได้นะครับ แต่บางทีไม่รู้ว่ามันคืออะไร ใช้ได้แต่ไม่รู้ความหมายทั้งหมด
ทดลองแบบง่ายๆ จากข้างล่าง แต่ไม่เข้าใจครับ
==============================
<?php
class Mainclass {
public function __construct(
$text){
$this->hello($text);
}
public function hello($text){
echo $text;
}
}
$alien = new Mainclass("test Echo");
?>
$text มันคืออะไร สัมพันกับส่วนอื่นใน Class ยังไง
พอรันออกมาแล้ว ทำไมมัน echo = test Echo
=============================