If I read this as a documentation page, this makes me scared:
`Order::create($validated + ['status' => 'pending']);`
What does it mean to add an array to something?
If I read this as a documentation page, this makes me scared:
`Order::create($validated + ['status' => 'pending']);`
What does it mean to add an array to something?
Order::create([...$validated, 'status' => 'pending']);
`$validated = ['key' => 'value']; $validated['status'] = 'pending'; Order::create($validated);`
No, because the example is showing concatenation of associative arrays. In Python, you'd use a dict, and you can't do `validated + {'status': 'pending'}`:
``` >>> validated = {} >>> validated + {'status': 'pending'} Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for +: 'dict' and 'dict' ```
You can do `validated | {'status': 'pending'}` since 3.9, though. I think using union or the * operator (e.g. `{*validated, 'status': 'pending'}`) looks less weird, but if you're a PHP programmer, you already know what + does here. In the end, it becomes bikeshedding.
[1,2,3] + [1,2,3]
// '1,2,31,2,3'
(never tried this in js before; so was amused by the result)