test.php
<?php
header('Content-type: text/html; charset=UTF-8');
class sample{
private $name;
private $a_name;
function __construct($name){
$this->name = $name;
$this->a_name = "C:/xampp/htdocs/sample/tmp/".$this->name;//成功
//$this->a_name = "tmp/".$name;//失敗
}
function __destruct() {
if(@rmdir($this->a_name)){
print("削除成功\n");
}else{
print("削除失敗\n");
}
}
}
$obj = new sample("aa");
?>
環境
OS:windows7 32bit (自作機)
xampp windows版1.74
PHP Version 5.3.5
解説
htdocs/sample/test.phpとし、htdocs/sample/tmp/にaaフォルダを作成しておく。
この時、destructでフォルダ削除をやってみたが、相対パスだと削除されなかった。
絶対パスに変えるとフォルダ削除ができた。