douli7841 2019-02-19 19:52
浏览 463

PHP / Laravel:复制对象和更改值的深度

It is possible to clone an instantiated object and change some value and create a new object with these changed values but without changing the values of the original object.

I know I can perform a deep copy using the command unserialize(serialize($swift)), but I have not found any way to change the values.

Source/Original:

Swift_Mailer {#777
  -transport: Swift_SmtpTransport {#779
    -handlers: array:1 [
      "AUTH" => Swift_Transport_Esmtp_AuthHandler {#783
        -authenticators: array:5 [
          0 => Swift_Transport_Esmtp_Auth_CramMd5Authenticator {#784}
          1 => Swift_Transport_Esmtp_Auth_LoginAuthenticator {#785}
          2 => Swift_Transport_Esmtp_Auth_PlainAuthenticator {#786}
          3 => Swift_Transport_Esmtp_Auth_NTLMAuthenticator {#787}
          4 => Swift_Transport_Esmtp_Auth_XOAuth2Authenticator {#788}
        ]
        -username: "myname@domain.local"
        -password: "mypassword"
        -auth_mode: null
        -esmtpParams: []
      }
    ]
    -capabilities: []
    -params: array:8 [
      "protocol" => "ssl"
      "host" => "mail.domain.com"
      "port" => 465
      "timeout" => 30
      "blocking" => 1
      "tls" => false
      "type" => 1
      "stream_context_options" => []
    ]

Changed:

Swift_Mailer {#777
  -transport: ...
        ]
        -username: "myname@otherdomain.local"
        -password: "otherpassword"
        ...
      }
    ]
    -capabilities: []
    -params: array:8 [
      "protocol" => "tls"
      "host" => "mail.otherdomain.net"
      "port" => 888
      ...
    ]
  • 写回答

1条回答 默认 最新

  • dongzhong2008 2019-02-19 19:55
    关注

    Not sure which PHP version you are running, but clone comes to mind. Note that objects within the objects etc might be an issue depending on if/how the __clone function is setup for the object.

    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示