LoginSignup
4
6

More than 5 years have passed since last update.

XAMPPにPHP7.0.0α1をインストール

Last updated at Posted at 2015-06-22

PHP7.1.0α1 / PHP7.1の新機能 / PHP7.0.0α1 / PHP5.6

http://php.net/
http://php.net/archive/2015.php#id2015-06-11-3
Windows用のPHP7ができてたのでXAMPP環境にインストールしてみます。
なおα版なので、真似る場合は自己責任で。

VCRUNTIME140.dll

Visual C++ 2015 ランタイムが必要なので、入っていなければインストールする。
http://stackoverflow.com/questions/30811668/php7-missing-vcruntime140-dll

ダウンロード

http://windows.php.net/qa/
PHP 7.0 (7.0.0alpha1)を選択。
32ビットPCでは「VC14 x86 Thread Safe」、64ビットは「VC14 x64 Thread Safe」をダウンロード。

インストール

既存のxampp/phpディレクトリを削除なりリネームなりで排除し、解凍したファイルをまるごとxampp/phpディレクトリにコピペ。

php.ini

php.ini-developmentをphp.iniにコピー。

必要なextensionを有効にする。
とりあえずphp_curl、php_gmp、php_mbstring、php_pdo_mysqlあたりのコメントを外した。
その他必要な設定。↓あたり。

date.timezone = Asia/Tokyo
mbstring.language = Japanese
mbstring.internal_encoding = UTF-8
mbstring.http_input = pass
mbstring.http_output = pass

xampp\apache\conf\extra\httpd-xampp.conf

php5_module、php5apache2_4.dll等、php5になっているところをphp7に変更。

起動

XAMPPコントロールパネルから起動。
色々足りてないが、とりあえず動作した。
20150622-php7.png

PHP7の機能

<?php
    // 厳密なタイプヒンティング
    declare(strict_types=1);

    /**
    * スカラー型タイプヒンティング、返り値のタイプヒンティング
    * @param int
    * @return bool booleanではないらしい
    */
    function hoge(int $i):bool{
        // return null; // Fatal error: Uncaught TypeException: Return value of hoge() must be an instance of boolean, null returned
        return true;
    }
    hoge(1);
    // hoge('1'); // Fatal error: Uncaught TypeException: Argument 1 passed to hoge() must be of the type integer, string given

    // 無名クラス
    $obj = new class(1) { // ()内はコンストラクタ引数
        public function __construct(int $i){
            $this->i = $i;
        }
    };

    // 環境によらず使える暗号論的擬似乱数生成器
    var_dump(random_int(100, 999));

    // 鮫
    var_dump("\u{9BAB}"); // ''では不可

    // 致命的エラー
    try {
        require_once('fail.php'); // fail.phpのパースエラーを受け取れる
        // a // このファイルがパースエラーの場合は死ぬ
    } catch (ParseException $e) {
        var_dump($e->getMessage()); // syntax error, unexpected end of file
    }

    // <=>
    var_dump(1<=>2, 2<=>2, 3<=>2 ); // 何故かApahceが落ちる

    // ??
    var_dump($_REQUEST['hoge'] ?? 'fuga'); // 未定義でもNoticeの発生しない?:

    // 商
    var_dump(intdiv(6, 4), 6%4); // 商1、余り2

    // ジェネレータ
    $gen = (function(){
        yield 1;
        yield from [2, 3];
        return 4;
        yield 5;
    })();
    foreach($gen as $v){
        var_dump($v); // 1,2,3になる。4は無い
    }
    var_dump($gen->getReturn()); // 4

    // ReflectionGenerator
    $gen = (function(){ yield from [5, 4, 3, 2, 1]; })();
    $ref = new ReflectionGenerator($gen); // 使った後のジェネレータは不可?
    var_dump(
        $ref->getExecutingLine(), // 現在yieldしてる行?
        $ref->getExecutingFile(), // 定義されてるファイル
        $ref->getTrace(), // []しか入ってこない
        $ref->getFunction(), // [ReflectionFunction]
        $ref->getExecutingGenerator() // $gen?
    );

何故か<=>演算子がApacheを巻き込んで落ちますが、それ以外はとりあえず動作しました。
まあ、まだα版ですし実用するべきではないでしょう。
パフォーマンス測定等は特にしていないので、高速化の結果は不明。
あとReflectionGeneratorなるクラスを見つけましたが詳細不明。

4
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
6