php symfony/var-dumperを使ってデバック関数var_dumpを見やすくする

phpのライブラリ「symfony/var-dumper」を使ってデバック関数var_dumpをより見やすくするための手順を記述してます。
環境
- OS windows10 pro 64bit
- Apache 2.4.43
- PHP 7.4.5
- Composer 1.10.5
※windows10にApacheのインストールはこちら
※windows10にphpのインストールはこちら
※Windows10にComposerのインストールはこちら
symfony/var-dumperインストール
phpが動作しているフォルダで、composerを使用してインストールします。
composer require symfony/var-dumper
<出力結果>
Using version ^5.1 for symfony/var-dumper
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 3 installs, 0 updates, 0 removals
- Installing symfony/polyfill-php80 (v1.17.1): Downloading (100%)
- Installing symfony/polyfill-mbstring (v1.17.1): Downloading (100%)
- Installing symfony/var-dumper (v5.1.2): Downloading (100%)
symfony/var-dumper suggests installing ext-intl (To show region name in time zone dump)
symfony/var-dumper suggests installing symfony/console (To use the ServerDumpCommand and/or the bin/var-dump-server script)
Writing lock file
Generating autoload files
3 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
自分の場合は、下記にインストールしました。

symfony/var-dumper利用
「C:\Apache24\htdocs」に「test.php」を下記のコードで作成します。
<?php
require __DIR__.'/vendor/autoload.php';
$array = [ "あいうえお", "あ", "あい", "あいう" ];
array_multisort( array_map( "strlen", $array ), SORT_ASC, $array );
dump($array);
実行結果は、下図のようになりデバック結果が見やすくなります。

illuminate/supportを使うと「dump($array); → dd($array); 」で可能になります。
composer require illuminate/support
<出力結果>
Using version ^7.19 for illuminate/support
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 9 installs, 0 updates, 0 removals
- Installing voku/portable-ascii (1.5.2): Downloading (100%)
- Installing symfony/translation-contracts (v2.1.3): Downloading (100%)
- Installing symfony/translation (v5.1.2): Downloading (100%)
- Installing psr/container (1.0.0): Loading from cache
- Installing nesbot/carbon (2.36.1): Downloading (100%)
- Installing psr/simple-cache (1.0.1): Loading from cache
- Installing illuminate/contracts (v7.19.0): Downloading (100%)
- Installing doctrine/inflector (2.0.3): Downloading (100%)
- Installing illuminate/support (v7.19.0): Downloading (100%)
voku/portable-ascii suggests installing ext-intl (Use Intl for transliterator_transliterate() support)
symfony/translation suggests installing symfony/config
symfony/translation suggests installing symfony/yaml
symfony/translation suggests installing psr/log-implementation (To use logging capability in translator)
illuminate/support suggests installing illuminate/filesystem (Required to use the composer class (^7.0).)
illuminate/support suggests installing moontoast/math (Required to use ordered UUIDs (^1.1).)
illuminate/support suggests installing ramsey/uuid (Required to use Str::uuid() (^3.7|^4.0).)
illuminate/support suggests installing symfony/process (Required to use the composer class (^5.0).)
illuminate/support suggests installing vlucas/phpdotenv (Required to use the Env class and env helper (^4.0).)
dd()利用例は下記となります。
<?php
require __DIR__.'/vendor/autoload.php';
$array = [ "あいうえお", "あ", "あい", "あいう" ];
array_multisort( array_map( "strlen", $array ), SORT_ASC, $array );
dd($array);
-
前の記事
Nuxt.js ライブラリ「vue-horizontal-list」をインストールしてタッチ対応な水平スクローラーを実装する 2020.07.08
-
次の記事
php 文字列を文字数によりソートする 2020.07.08
コメントを書く