基于 数组相关函数 操作数组后,同样的输入,在不同执行顺序下的差异的分析(include、引用)
1、参考:在 Laravel 6 中,基于 数组相关函数 操作数组后,同样的输入,在不同执行顺序下的差异的分析(include、引用)。https://www.shuijingwanwq.com/2023/06/13/7716/
2、当时的解决方案:将 $value 替换为 $sectionSettingValue,临时规避掉引用的变量名重名的问题
3、之后又存在类似的问题,需要能够快速定位是哪些变量重名导致的问题。决定将执行有误的文件中的变量都在文件开头打印出来。最后将打印结果中不为 null 的,全部 unset() 掉。
1 2 3 4 5 6 7 8 9 10 11 | \Illuminate\Support\Facades\Log::info( 'schema.v2.1.80' , [ '$sectionKey' => $sectionKey ?? null, '$section' => $section ?? null, '$blockKey' => $blockKey ?? null, '$block' => $block ?? null, '$blockOrderKey' => $blockOrderKey ?? null, '$blocks' => $blocks ?? null, ] ); |
4、打印结果如下,确认在上一次的执行后,变量:$sectionKey、$section、$blockKey、$block、$blockOrderKey、$type 皆不为 null,全部需要销毁掉。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | [2023-09-04 10:43:45] local.INFO: schema.v2.1.80 { "$sectionKey": "image-1", "$section": { "type": "image", "disabled": false, "settings": { "heading": "", "heading_align": "center" }, "blocks": { "column-0": { "type": "column", "settings": { "image": "https://xxx-s3.s3.us-east-2.amazonaws.com/image/736589fac73c7dfdbf61efadb49a95fb9af16efb.jpeg", "mobile_image": "https://cdn.xxx.com/image/2022/03/200062b82e8cbae7cf7c48b425a33260686fd4aa3e6ed656901cb4cc7a283487.jpeg", "url": "/" } }, "column-1": { "type": "column", "settings": { "image": "https://xxx-s3.s3.us-east-2.amazonaws.com/image/736589fac73c7dfdbf61efadb49a95fb9af16efb.jpeg", "mobile_image": "https://cdn.xxx.com/image/2022/03/200062b82e8cbae7cf7c48b425a33260686fd4aa3e6ed656901cb4cc7a283487.jpeg", "url": "/" } } } }, "$blockKey": "column-1", "$block": { "type": "column", "settings": { "image": "https://xxx-s3.s3.us-east-2.amazonaws.com/image/736589fac73c7dfdbf61efadb49a95fb9af16efb.jpeg", "mobile_image": "https://cdn.xxx.com/image/2022/03/200062b82e8cbae7cf7c48b425a33260686fd4aa3e6ed656901cb4cc7a283487.jpeg", "url": "/" } }, "$blockOrderKey": 8, "$type": [ "search", "all_collections" ] } |
5、销毁变量的代码如下
1 | unset( $sectionKey , $section , $blockKey , $block , $blockOrderKey , $type ); |
近期评论