在laravel中,dd()屬於laravel輔助函數;dd函數用於輸出給定的值並結束腳本運行,可以列印laravel中的所有變量,語法為「dd($value1,$value2 ...)」。
本文操作環境:Windows10系統、Laravel6版、Dell G3電腦。
laravel中dd屬於函數嗎
dd 函數輸出給定的值並結束腳本運行:
dd($value); dd($value1, $value2, $value3, ...);
範例PHP全域使用Laravel輔助函數dd:
全域composer.json
"require": { "squizlabs/php_codesniffer": "*", "fxp/composer-asset-plugin": "^1.4", "symfony/var-dumper": "3.3.16" }
設定PHP.ini
auto_prepend_file = "C:UsersMSAppDataRoamingComposervendorautoload.php"
更新Composer
composer global update
#更新後重啟apache就可以全域使用函數dump()
dd() 方法
全域composer.json
# 新增 autoload "autoload": { "files": [ "D:/web/php/debugHelper.php" ] }
新debugHelper.php
# install symfony/var-dump to your project # composer require symfony/var-dumper // use namespace use ComponentVarDumperClonerVarCloner; use ComponentVarDumperDumperCliDumper; use ComponentVarDumperDumperHtmlDumper as SymfonyHtmlDumper; /** * Class HtmlDumper */ class HtmlDumper extends SymfonyHtmlDumper { /** 大专栏 PHP 全局使用 Laravel 辅助函数 ddnt"> * Colour definitions for output. * * @var array */ protected $styles = [ 'default' => 'background-color:#fff; color:#222; line-height:1.2em; font-weight:normal; font:12px Monaco, Consolas, monospace; word-wrap: break-word; white-space: pre-wrap; position:relative; z-index:100000', 'num' => 'color:#a71d5d', 'const' => 'color:#795da3', 'str' => 'color:#df5000', 'cchr' => 'color:#222', 'note' => 'color:#a71d5d', 'ref' => 'color:#a0a0a0', 'public' => 'color:#795da3', 'protected' => 'color:#795da3', 'private' => 'color:#795da3', 'meta' => 'color:#b729d9', 'key' => 'color:#df5000', 'index' => 'color:#a71d5d', ]; } /** * Class Dumper */ class Dumper { /** * Dump a value with elegance. * * @param mixed $value * @return void */ public function dump($value) { if (class_exists(CliDumper::class)) { $dumper = 'cli' === PHP_SAPI ? new CliDumper : new HtmlDumper; $dumper->dump((new VarCloner)->cloneVar($value)); } else { var_dump($value); } } } if (! function_exists('dd')) { /** * Dump the passed variables and end the script. * * @param mixed * @return void */ function dd(...$args) { foreach ($args as $x) { (new Dumper)->dump($x); } die(1); } } if (! function_exists('dda')) { /** * Dump the passed array variables and end the script. * * @param mixed * @return void */ function dda(...$args) { foreach ($args as $x) { (new Dumper)->dump($x->toArray()); } die(1); } }
相關推薦:最新的五個Laravel影片教學
#以上是laravel中dd屬於函數嗎的詳細內容。更多資訊請關注PHP中文網其他相關文章!