1
1

More than 1 year has passed since last update.

xdebugがPHP環境に入っているかどうかでvar_dump()の出力形式が変わる

Last updated at Posted at 2022-06-29
../

xdebugがPHP環境に入っているかどうかでvar_dump()の出力形式が変わることを知った。

以前、var_dump2($user)でダンプすると、以下の感じだった。シンプルでいい。var_dump2()は「行数を節約するvar_dump()を書いてみた」を参照のこと。

class samples\User#1 (4) {
  private $mail => string(11) "aaa@xxx.com"
  private $id => string(4) "U001"
  private $name => string(12) "池田さん"
  public $name => string(12) "山本さん"
}

XAMPPを入れ替えて、var_dump2($user)を試すと、以下の感じに変わってしまっていた。継承したクラスまで識別しようとしていて、文字数が多くてスッキリしない感じになる。

object(samples\User)#1 (4) {
  ["mail":"samples\User":private] => string(11) "aaa@xxx.com"
  ["id":"samples\Identifier":private] => string(4) "U001"
  ["name":"samples\Identifier":private] => string(12) "池田さん"
  ["name"] => string(12) "山本さん"
}

調べてみると、xdebugがPHP環境に入っているかどうかでvar_dump()の出力形式が変わるようだ。

php.ini に以下を追加し、Eclipseを再起動して試すとシンプルな出力形式になる。Zend extensionのロード指定はフルパスで書く必要があるそうだ。

zend_extension = "C:\pleiades-xxx\xampp\php\ext\php_xdebug.dll"
class samples\User#1 (4) {
  private $mail => string(11) "aaa@xxx.com"
  private $id => string(4) "U001"
  private $name => string(12) "池田さん"
  public $name => string(12) "山本さん"
}

php.ini のzend_extensionをコメントアウトし、Eclipseを再起動して試すとスッキリしない出力形式になる。先頭カラムに;を追加してます。

; zend_extension = "C:\pleiades-xxx\xampp\php\ext\php_xdebug.dll"
object(samples\User)#1 (4) {
  ["mail":"samples\User":private] => string(11) "aaa@xxx.com"
  ["id":"samples\Identifier":private] => string(4) "U001"
  ["name":"samples\Identifier":private] => string(12) "池田さん"
  ["name"] => string(12) "山本さん"
}

ちなみに、zend_extension の値は ini_set()では変更できないので、直接 php.ini を編集する必要がある。

../
1
1
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
1
1