您好,登錄后才能下訂單哦!
本篇文章為大家展示了如何理解PHP全局使用Laravel輔助函數(shù)dd,內(nèi)容簡明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
dump() 方法
全局 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就可以全局使用函數(shù) 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 namespaceuse ComponentVarDumperClonerVarCloner;use ComponentVarDumperDumperCliDumper;use ComponentVarDumperDumperHtmlDumper as SymfonyHtmlDumper;/** * Class HtmlDumper */class HtmlDumper extends SymfonyHtmlDumper{ /**大專欄 PHP 全局使用 Laravel 輔助函數(shù) 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); }}
更新composer自動(dòng)加載
composer global dump-autoload
更新后就可以全局使用函數(shù) dd()
上述內(nèi)容就是如何理解PHP全局使用Laravel輔助函數(shù)dd,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。