LoginSignup
8
8

More than 5 years have passed since last update.

PHP5.4と.5.5におけるemptyの挙動の違い

Last updated at Posted at 2014-08-21

少しハマったのでメモ。PHP5.4と5.5で挙動が違います。カッコ内で代入するときにPHP5.4だとParse errorに、PHP5.5だと正常に動作します。

PHP5.4では

PHP5.4
$ php -v
PHP 5.4.24 (cli) (built: Jan 19 2014 21:32:15)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

$ php -r 'empty($test = "test");'

Parse error: parse error, expecting `')'' in Command line code on line 1

PHP5.5では

PHP5.5
$ php -v
PHP 5.5.15 (cli) (built: Aug 21 2014 15:44:52)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies

$ php -r 'empty($test = "test");'

PHPマニュアルを見ると、5.5で挙動が変わってました。5.5では式も評価するようになっています。

PHPマニュアル

PHP__empty_-_Manual.png

8
8
0

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
8
8