第 77章その他の質問

ここでは他のカテゴリに分類することができないような質問を扱います。

1. bz2で圧縮された Windows マニュアルはどのように扱えばいいのですか?
2. What does & beside argument mean in function declaration of e.g. asort()?
3. 私はどのように register_globals を扱うべきか?

1. bz2で圧縮された Windows マニュアルはどのように扱えばいいのですか?

bz2 ファイルを処理することができるアーカイバを持っていない場合、 RedHat からコマンドラインツールを ダウンロードしてください。 (詳細は下記の情報を参照)

コマンドラインツールを使いたくない場合は、Stuffit Expander, UltimateZip, 7-Zip, Quick Zip のようなフリーのツールを使用することも可能です。 WinRAR または Power Archiver のようなツールを持っている場合、簡単にbz2ファイルを解凍できます。 Total Commander(以前はWindows Commander)を使用している場合は、 bz2 用のプラグインを Total Commander のサイトから無料で手に入れることが出来ます。

Redhat から入手可能な bzip2 コマンドラインツール:

Windows 2000 SP2 のユーザは バージョン1.0.2 を、他の全ての Windows ユーザはバージョン 1.00 を使用してください。 ダウンロードしたら実行ファイルの名前を bzip2.exe へ変更してください。 そしてそれをパスの通ったディレクトリ、例えば C:\Windows(ドライブ名は貴方のシステムにあわせて適宜変更してください) へコピーしてください。

注意: lang は使用する言語を意味し、 pdf のようにxは指定した形式を表します。 php_manual_lang.x.bz2 を解凍するには以下のようにします。

  • コマンドプロンプトウィンドウを開きます

  • ダウンロードした php_manual_lang.x.bz2 を保存したディレクトリに cd コマンドを使用して移動します。

  • bzip2 -d php_manual_lang.x.bz2 を実行すると php_manual_lang.x というファイルが同じディレクトリに生成されます。

分割 HTML 版アーカイブ(php_manual_lang.tar.bz2) をダウンロードした場合でも手順は同じです。 唯一の違いは、bzip2 コマンドの実行後に php_manual_lang.tar が生成されることです。 tar 形式のファイルは WinZip といったアーカイバで扱うことができます。

2. What does & beside argument mean in function declaration of e.g. asort()?

It means that the argument is passed by reference and the function will likely modify it corresponding to the documentation. You can pass only variables this way and you don't need to pass them with & in function call (it's even deprecated).

3. 私はどのように register_globals を扱うべきか?

For information about the security implications of register_globals, read the security chapter on Using register_globals.

It's preferred to use superglobals, rather than relying upon register_globals being on.

If you are on a shared host with register_globals turned off and need to use some legacy applications, which require this option to be turned on, or you are on some hosting server, where this feature is turned on, but you would like to eliminate security risks, you might need to emulate the opposite setting with PHP. It is always a good idea to first ask if it would be possible to change the option somehow in PHP's configuration, but if it is not possible, then you can use these compatibility snippets.

例 77-1. Register Globals をエミュレートする

これは register_globals On をエミュレートするでしょう。

<?php
// register_globals on をエミュレートする
if (!ini_get('register_globals')) {
    
$superglobals = array($_SERVER, $_ENV,
        
$_FILES, $_COOKIE, $_POST, $_GET);
    if (isset(
$_SESSION)) {
        
array_unshift($superglobals, $_SESSION);
    }
    foreach (
$superglobals as $superglobal) {
        
extract($superglobal, EXTR_SKIP);
    }
}
?>

これは register_globals Off をエミュレートするでしょう。

<?php
// register_globals off をエミュレートする
if (ini_get('register_globals')) {
    
$superglobals = array($_SERVER, $_ENV,
        
$_FILES, $_COOKIE, $_POST, $_GET);
    if (isset(
$_SESSION)) {
        
array_unshift($superglobals, $_SESSION);
    }
    foreach (
$superglobals as $superglobal) {
        foreach (
$superglobal as $global => $value) {
            unset(
$GLOBALS[$global]);
        }
    }
}
?>