m0_37683990 2022-02-17 18:32 采纳率: 0%
浏览 47

PHP的 Laravel 框架和TP5,为什么要把结果转对象来处理呢??

例如,我用框架的Model执行了一下mysql 数据库查询之后,返回结果为:


Array
(
    [0] => app\common\model\walmart\WalmartListing Object
        (
            [query:protected] => erp\ErpQuery
            [virtualFields:protected] => Array
                (
                )

            [connection:protected] => Array
                (
                )

            [name:protected] => WalmartListing
            [table:protected] => 
            [class:protected] => app\common\model\walmart\WalmartListing
            [error:protected] => 
            [validate:protected] => 
            [pk:protected] => 
            [field:protected] => Array
                (
                )

            [readonly:protected] => Array
                (
                )

            [visible:protected] => Array
                (
                )

            [hidden:protected] => Array
                (
                )

            [append:protected] => Array
                (
                )

            [data:protected] => Array
                (
                    [id] => 11
                    [account_id] => 37
                    [vid] => 15
                    [sku_id] => 100529
                    [variation_sku] => LA0Q3C9FBN99MF2601
                    [price] => 23121.00
                    [inventory] => 5
                )

            [change:protected] => Array
                (
                )

            [auto:protected] => Array
                (
                )

            [insert:protected] => Array
                (
                )

            [update:protected] => Array
                (
                )

            [autoWriteTimestamp:protected] => 
            [createTime:protected] => create_time
            [updateTime:protected] => update_time
            [dateFormat:protected] => 
            [type:protected] => Array
                (
                )

            [isUpdate:protected] => 1
            [updateWhere:protected] => 
            [relation:protected] => 
            [failException:protected] => 
            [useGlobalScope:protected] => 1
            [batchValidate:protected] => 
            [resultSetType:protected] => array
            [relationWrite:protected] => 
            [filterClass:protected] => 
        )

)

为什么不是返回简简单单的数组呢?用惯了旧框架,和原生,早就习惯了用数组处理。

这个把结果转成对象的形式返回,有什么好处吗?目的是啥?

求详细解答下,谢谢啦

  • 写回答

2条回答 默认 最新

  • CSDN专家-陈畅didphp 2022-02-18 10:24
    关注

    返回对象是因为他们里面基本都是封装的类,有时候需要这些结果这些类和这些类中的方法,去再次的进行一些扩展,数组会方便读取,但是不方便扩展。

    评论

报告相同问题?

问题事件

  • 创建了问题 2月17日

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算