Skip to content

Instantly share code, notes, and snippets.

@DQNEO
Last active February 16, 2016 09:44
Show Gist options
  • Save DQNEO/09ee78f8af7f71b07db3 to your computer and use it in GitHub Desktop.
Save DQNEO/09ee78f8af7f71b07db3 to your computer and use it in GitHub Desktop.
PHP5.5で、終了タグ "?>" の有無でパーサの挙動が変わるケース
<?php
declare(encoding='UTF-8');
/* あ */
<?php
declare(encoding='UTF-8');
/* あ */
?>
$ php -l a.php
PHP Warning: Unexpected character in input: ' in a.php on line 6
$ php -l b.php
No syntax errors detected in b.php
$ php -i | grep _encoding | sort -r
zend.script_encoding => EUC_JP => EUC_JP
mbstring.internal_encoding => EUC-JP => EUC-JP
iconv.output_encoding => ISO-8859-1 => ISO-8859-1
iconv.internal_encoding => ISO-8859-1 => ISO-8859-1
iconv.input_encoding => ISO-8859-1 => ISO-8859-1
$ php --version
PHP 5.5.12 (cli) (built: May 2 2014 19:53:49)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
@DQNEO
Copy link
Author

DQNEO commented Jul 23, 2014

PHP 5.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

@DQNEO
Copy link
Author

DQNEO commented Jul 23, 2014

➜ php-5.5.14 ./sapi/cli/php -d zend.multibyte=On -d zend.script_encoding="EUC_JP" /vagrant/a.php

Warning: Unexpected character in input: ' in /vagrant/a.php on line 6
[Wed Jul 23 13:54:03 2014] Script: '/vagrant/a.php'
/home/vagrant/src/php-5.5.14/ext/mbstring/mbstring.c(612) : Freeing 0x7F34B19D51B0 (109 bytes), script=/vagrant/a.php
=== Total 1 memory leaks detected ===
➜ php-5.5.14 ./sapi/cli/php -v
PHP 5.5.14 (cli) (built: Jul 23 2014 13:46:57) (DEBUG)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies

@DQNEO
Copy link
Author

DQNEO commented Jul 23, 2014

php5.7.0-devでも発生

➜  php-src git:(master) ./sapi/cli/php -d zend.multibyte=On -d mbstring.internal_encoding="EUC_JP"  /vagrant/a.php

Warning: Unexpected character in input:  ' in /vagrant/a.php on line 6
➜  php-src git:(master) ./sapi/cli/php -v
PHP 5.7.0-dev (cli) (built: Jul 23 2014 15:45:55) (DEBUG)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.7.0-dev, Copyright (c) 1998-2014 Zend Technologies

@DQNEO
Copy link
Author

DQNEO commented Feb 16, 2016

本家にissue登録した。
https://bugs.php.net/bug.php?id=67681

@DQNEO
Copy link
Author

DQNEO commented Feb 16, 2016

PHP 5.6.17でも発生。
PHP7.0.3 だと直っていた。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment