Does PHP feature short hand syntax for objects?

前端 未结 7 667
囚心锁ツ
囚心锁ツ 2020-12-06 04:04

In javascript you can easily create objects and Arrays like so:

var aObject = { foo:\'bla\', bar:2 };
var anArray = [\'foo\', \'bar\', 2];

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-06 04:32

    For simple objects, you can use the associative array syntax and casting to get an object:

     'bar');
    echo $obj->foo; // yields "bar"
    

    But looking at that you can easily see how useless it is (you would just leave it as an associative array if your structure was that simple).

提交回复
热议问题