Skip to content

Implement Size destructuring#1487

Merged
olivervogel merged 17 commits into
developfrom
feature/size-deconstructing
May 15, 2026
Merged

Implement Size destructuring#1487
olivervogel merged 17 commits into
developfrom
feature/size-deconstructing

Conversation

@olivervogel
Copy link
Copy Markdown
Member

@olivervogel olivervogel commented May 13, 2026

By decoupling Size from Polygon.

[$width, $height] = $image->size();
['width' => $width, 'height' => $height] = $image->size();

Closes #1480

@olivervogel olivervogel marked this pull request as draft May 13, 2026 13:59
@olivervogel olivervogel changed the title Implement Size deconstructing Implement Size destructuring May 13, 2026
@olivervogel olivervogel marked this pull request as ready for review May 14, 2026 06:36
@Abdooo2235
Copy link
Copy Markdown

Thanks for picking this up — the shape is exactly what I had in mind, and the keyed-destructuring is a nice addition.

One small thing on Size::offsetGet: the default branch throws \ErrorException. That's conventionally reserved for error-handler-converted PHP errors. For "unknown offset on a read-only ArrayAccess object," PHP's stdlib convention is \OutOfBoundsException (or \InvalidArgumentException — which is also what Size's constructor uses for negative width/height in this codebase). Happy to send a small PR against your branch if useful.

Either way, looking forward to seeing this land.

@olivervogel
Copy link
Copy Markdown
Member Author

olivervogel commented May 14, 2026

I see what you mean. I don't think InvalidArgumentException is quite the right choice here, since this isn't a function argument in the traditional sense and the exception is for semantically for bad function/method arguments.

I replaced it with RuntimeException, which matches the other ArrayAccess methods and keeps it in the libraries exception hierarchy.

@olivervogel olivervogel merged commit 969abf8 into develop May 15, 2026
12 checks passed
@olivervogel olivervogel deleted the feature/size-deconstructing branch May 15, 2026 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable array destructuring of Size::class with width & height

2 participants