2011-11-16

Magical Methods in PHP Class

Named starting with __ as magical

__construct()
will be called on each newly-created object

__destruct()
will be called there are no other references to a particular object in any order during the shutdown sequence.

__isset()
is triggered by calling isset() or empty() on inaccessible properties.

__unset()
is invoked when unset() is used on inaccessible properties.

__set()
is run when writing data to inaccessible properties.

__get()
is utilized for reading data from inaccessible properties.

__call()
is triggered when invoking inaccessible methods in an object context.

__callStatic()
is triggered when invoking inaccessible methods in a static context.

__sleep()
serialize() checks __sleep().
executed prior to any serialization.

__wakeup()
unserialize() checks __wakeup().
this function can reconstruct any resources that the object may have.

__toString()
when it is treated like a string. must return a string

__invoke()
call an object as a function.

__set_state()
be called for classes exported by var_export()

__clone()
Once the cloning is complete,
if a __clone() method is defined,
then the newly created object's __clone() method will be called

Reference:

http://php.net/manual/en/language.oop5.magic.php 石頭閒語 - http://blog.roodo.com/rocksaying/archives/10796767.html
石頭閒語 - http://blog.roodo.com/rocksaying/archives/2683180.html

[PHP] Equal vs. Identical

Equal: ==
Identical: ===
兩個都是用來進行比較運算的 "Comparison Operators"
有什麼不一樣呢?

如果是要比較不同的資料型態時,
使用 "Equal" 時,會先轉換成相同的資料型態,再進行比較
使用 "Identical" 時,不會轉換資料型態


Reference:
http://blog.roodo.com/rocksaying/archives/2565180.html
http://www.php.net/manual/en/language.operators.comparison.php
http://www.php.net/manual/en/types.comparisons.php

2011-10-30

GTK-Warning: pixmap

作業系統換上全新的 Ubuntu 11.10 ,遇到了一些問題
新出來的東西嘛,難免的

錯誤訊息:
Gtk-WARNING **: 無法在module_path 中找出佈景主題引擎:‘pixmap’

解決方案:
安裝缺少的套件就好了~
sudo apt-get install gtk2-engines-pixbuf

Reference:
Tsung's Blog - Ubuntu 修復 GTK WARNING(module_path, pixmap)

2011-10-03

ID3 Tag - 轉換編碼

在 Linux 上要播 MP3 時,常常會看到音樂的相關資訊變成亂碼,
這是因為 MP3 裡的 ID3 tags 編碼不是 UTF-8。

要解決這個問題不難,有個工具可以輕鬆的轉換編碼,就是 mid3iconv

安裝

只要安裝 python-mutagen 套件,就可以有好用的 mid3iconv 可以用了
$ sudo apt-get install python-mutagen

操作方法

裝好之後就可以開始轉換了。

如果確定要轉換編碼的 ID3 Tag 原本是 big5 的話,
就用以下指令轉換當前資料夾裡的所有 MP3 的 ID3 編碼
$ mid3iconv -e big5 *.mp3 參數
-e 編碼
    資料原本的編碼
-p, --dry-run
    不會改變原檔案

更進階的用法:
轉換目前目錄下所有子目錄的 MP3
find . -iname "*.mp3" -execdir mid3iconv -e big5 {} \;
Ubuntu Linux - 用mid3iconv及exfalso批次整理舊MP3的ID3標籤
[筆記]在Ubuntu下大量轉換ID3之編碼

2011-06-01

[Apache] 使用者自己的網頁目錄 & Config Indexes

要讓使用者有自己的網頁目錄不麻煩
把 apache2 的 userdir mod 啟動就可以了


在 ubuntu 下的方法:
# a2enmod userdir
# /etc/init.d/apache2 restart


預設的網頁目錄是
~/public_html/
就在 userdir.conf 裡的
<Directory /home/*/public_html>

網址則是
http://localhost/~user/

還可以設定哪些 user 可以使用 userdir
# 預設是 disabled root
UserDir disabled root

如果 userdir 下的 php 沒辦法打開,會變成下載 php 檔的話,那要調整一下 apache 的 php 設定

就在 /etc/apache2/mods-available/php5.conf 裡有註明
# To re-enable php in user directories comment the following lines
# (from to .) Do NOT set it to On as it
# prevents .htaccess files from disabling it.


就如 conf 檔裡所看到的,comment the following lines 吧

另外,這設定好像是 php5.3 才新加的

避免 /var/www/ 的目錄中沒有 index.html 而被瀏覽者看到目錄中的檔案或資料夾


# vim /etc/apache2/sites-enabled/000-default
<Directory /var/www/>:
Options Indexes FollowSymLinks MultiViews #將 Indexes 刪除
AllowOverride None
Order allow,deny
allow from all
</Directory>

# /etc/init.d/apache2 restart