LoginSignup
9

More than 5 years have passed since last update.

PHP5.6 Source Install

Last updated at Posted at 2014-08-29

RELEASE NEWS
* http://jp1.php.net/archive/2014.php#id2014-08-28-1

非互換の変更
* http://jp1.php.net/manual/ja/migration56.incompatible.php

Goal

* php5.6の新機能を確認する

Preparation

uname -a
  # Linux *** 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

cat /etc/issue
  # CentOS release 6.5 (Final)
  # Kernel \r on an \m

Download

http://jp1.php.net/downloads.php
* 圧縮形式を選んで、一番近いミラーを選んでリンク先のアドレスをコピー

sudo su
cd /usr/local/src
wget "http://jp1.php.net/get/php-5.6.0.tar.gz/from/this/mirror" -O php-5.6.0.tar.gz
tar zxvf php-5.6.0.tar.gz

Install

cd php-5.6.0

./configure --help

# --with-apxs2=/usr/local/apache/bin/apxs
# apacheの{apache_path}/modules/libphp5.soを上書きする
# このオプションをつけない場合は、libs/libphp5.soをapacheディレクトリにコピーする

./configure \
--prefix=/usr/local/php-5.6.0 \
--enable-mbstring \
--enable-libgcc \
--enable-pcntl \
--with-zlib \
--with-openssl \
--with-curl \
--with-config-file-scan-dir=/usr/local/php-5.6.0/lib/conf.d \
--enable-phpdbg

## --enable-phpdbgオプションをつけると5.6の新機能php-dbgを使える

# make clean
make
make test
make install

make testの結果、FAIL:1, WARN:5件あったが解消しきれなかったので無視して進んだ

=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Bug #32001 (xml_parse*() goes into infinite loop when autodetection in effect), using UTF-* [ext/xml/tests/bug32001.phpt]
=====================================================================

=====================================================================
WARNED TEST SUMMARY
---------------------------------------------------------------------
zend multibyte (2) [ext/mbstring/tests/zend_multibyte-02.phpt] (warn: XFAIL section but test passes)
zend multibyte (6) [ext/mbstring/tests/zend_multibyte-06.phpt] (warn: XFAIL section but test passes)
zend multibyte (8) [ext/mbstring/tests/zend_multibyte-08.phpt] (warn: XFAIL section but test passes)
zend multibyte (10) [ext/mbstring/tests/zend_multibyte-10.phpt] (warn: XFAIL section but test passes)
zend multibyte (11) [ext/mbstring/tests/zend_multibyte-11.phpt] (warn: XFAIL section but test passes)
=====================================================================

Check

Constant Scalar

スカラの式として定数を定義できるようになった

constant_scalar.php
<?php

const PROTOCOL = 'http';
const DOMAIN = 'metheglin.jp';
const BASE_URL = PROTOCOL . '://' . DOMAIN . '/';

echo BASE_URL;

/usr/local/php-5.5.4/bin/php constant_scalar.php

PHP Parse error:  syntax error, unexpected '.', expecting ',' or ';' in /home/vagrant/work/constant_scalar.php on line 5

Parse error: syntax error, unexpected '.', expecting ',' or ';' in /home/vagrant/work/constant_scalar.php on line 5

/usr/local/php-5.6.0/bin/php constant_scalar.php

http://metheglin.jp/

Variadic

"..."記法で可変長引数を配列で受け取れるようになり、関数宣言部でそれを明示できるようになった

variadic.php
<?php

function func(...$params) {
  var_dump($params);
}

func(1, 'test', 123456.789, ['aaa', 'bbb']);

/usr/local/php-5.6.0/bin/php variadic.php

array(4) {
  [0]=>
  int(1)
  [1]=>
  string(4) "test"
  [2]=>
  float(123456.789)
  [3]=>
  array(2) {
    [0]=>
    string(3) "aaa"
    [1]=>
    string(3) "bbb"
  }
}

配列引数を"..."でアンパックすることもできる

param_unpack.php
<?php

function func($a, $b, $c) {
  var_dump($a);
  var_dump($b);
  var_dump($c);
}

$array = [256, 'acdefghijklmn', [1,2,3]];

func(...$array);

/usr/local/php-5.6.0/bin/php php:param_unpack.php

int(256)
string(13) "acdefghijklmn"
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}

ただし、文字列のキーを含む配列はunpackできない

param_unpack_strkey.php
<?php

function func($a, $b, $c) {
  var_dump($a);
  var_dump($b);
  var_dump($c);
}

$array = [
  'first' => 256,
  'second' => 'bacdefghijklmn',
  'third' => [1,2,3],
];

func(...$array);

/usr/local/php-5.6.0/bin/php php:param_unpack_strkey.php

Catchable fatal error: Cannot unpack array with string keys in /home/vagrant/work/param_unpack.php on line 15

Exponentiation

"**"演算子で累乗を計算できるようになった

exponential.php
<?php
echo 2 ** 32;

/usr/local/php-5.6.0/bin/php exponential.php

4294967296

Function and constant importing

関数と定数も別の名前空間からインポートができるようになった

importable_func_const.php
<?php

namespace Diagram\Basic {
  const PI = 3.14159265358979;
  function get_circumference($diameter) {
    return $diameter * PI;
  }
}

namespace {
  use const Diagram\Basic\PI;
  use function Diagram\Basic\get_circumference;

  function get_circle_area($radius) {
    return ($radius ** 2) * PI;
  }

  function get_cylinder_area($bottom_radius, $height) {
    $bottom_diameter = $bottom_radius * 2;
    return ( get_circle_area($bottom_radius) * 2 ) + ( get_circumference($bottom_diameter) * $height );
  }

  // 底面の半径が10cm, 高さが5cmの 円柱の高さを求める
  echo get_cylinder_area(10, 5) . 'cm';
}

/usr/local/php-5.6.0/bin/php importable_func_const.php

942.47779607694cm

phpdbg

phpdbgがデフォルトで組み込まれた(--enable--phpdbgオプションをつけてビルドする必要がある)
http://phpdbg.com/docs/getting-started

/usr/local/php-5.6.0/bin/phpdbg
[Welcome to phpdbg, the interactive PHP debugger, v0.4.0]
To get help using phpdbg type "help" and press enter
[Please report bugs to <http://github.com/krakjoe/phpdbg/issues>]
phpdbg> help
...

Resuable php://input

GMP supports overloading

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
9