On 4 May 2016 10:41 pm, "Rowan Collins" <rowan.coll...@gmail.com> wrote: > > > You could either think of this as "setting lots of variables": > > new Foo { $bar = 1, $baz = 2 } > > or you could think of it as "an object literal like an array literal": > > new Foo { 'bar' => 1, 'baz' => 2 } >
I think a $ is only necessary to disambiguate, ie between variable and constant. It isn't necessary as a prefix for properties when it is unambiguous that the thing is a property. Eg property access is ->foo, not ->$foo. I don't think the string literal syntax is appropriate for classes/structs/records which have a defined, static structure. You would use that when you're talking about a hash table/associative array/map/dict, for which the key is often an arbitrary expression. So I would go with plain property name without prefix. It certainly looks nicer in the context of annotations. > > And then we also need to think about sitting nicely with anonymous class syntax. Not to mention Joe's proposal for lexical scope: https://wiki.php.net/rfc/lexical-anon > AFAIK anonymous classes always start with "new class ..", so there would be no ambiguity. It would be an optional {...} part that follows a class instantiation, anonymous or not. > > For the record, I like the idea, if we can come up with a consistent plan for how these pieces of syntax will work together, and not paint ourselves into an ASCII-art hole... > It sounds like this conversation has been had before (but I'm not sure about instantiate-and-set-properties specifically), but nonetheless the problem remains and it's a common pain point for me and fellow devs. Annotations sound like the ideal time to address it since they also need to instantiate classes and set public properties in one expression.