Hi Andrea, On Sun, Mar 29, 2020 at 10:31 AM Andrea Faulds <a...@ajf.me> wrote: > > > (function ($obj) { > $foo = "foo"; > $bar = "bar"; > $baz = "baz"; > > $vars = get_defined_vars(); > foreach ($vars as $key => $value) { > $obj->$key = $value; > } > })($object); > > It's not very elegant though, and unfortunately you can't move the > get_defined_vars() part to another function.
In an early version of my RFC I had included a long section of examples of how you could do what COPA does but with current syntax, each with its flaws. I've tried everything from magic methods, anonymous classes and closures :-) I removed it because it didn't seem to add much to the discussion and the RFC became too long for a thorough read. Thanks for the creativity though, I like playing with ideas like that, but I must confess I frown upon functions like get_defined_vars() and extract(), if you know what I mean :-D I'd like to iterate that I believe the force of COPA is it's simplicity - and I think it's gone unnoticed for many that the only thing COPA adds to existing syntax is a set of square brackets around the assignments. Everything else is familiar. I repeat, the only difference between these two snippets is the [...]: ------------------ $myObj->a = 1; $myObj->b = 2; $myObj->c = 3; ------------------ $myObj->[ a = 1, b = 2, c = 3, ]; ---------------- -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php