How can I access a deep object property named as a variable (dot notation) in php?

前端 未结 5 1505
醉梦人生
醉梦人生 2020-11-27 08:05

There are many questions similar to this, however this is slightly different since it\'s about deep object property access, not just one level of depth.

Let\'s say I

5条回答
  •  囚心锁ツ
    2020-11-27 08:43

    You can use my JSON package using Composer:

    composer require machitgarha/json
    

    For example:

    $userJson = new MAChitgarha\Component\JSON(new User());
    
    $userJson->set("foo", new Foo());
    $userJson->set("foo.bar", "Hello World");
    
    $userJson->get("foo.bar"); // Hello World 
    

提交回复
热议问题