Skip to content

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Nov 2, 2019

That parameter is mostly useless in practise, and likely has been
directly ported from the underlying gdImagePolygon() and friends,
which require that parameter since the number of elements of the point
array would otherwise be unknown. Typical usages of imagepolygon(),
imageopenpolygon() and imagefilledpolygon() pass count($points)/2
or hard-code this value as literal. Since explicitly specifying this
parameter is annoying and error-prone, we offer the possibility to omit
it, in which case the $points array must have an even number of
elements, and the number of points is calculated as count($points)/2.

We deprecate explicitly passing the $num_points parameter, but keep
the sloppy behavior of the functions in this case (for instance, having
an odd number of elements in $points).


See also the internals discussion from a while back.

That parameter is mostly useless in practise, and likely has been
directly ported from the underlying `gdImagePolygon()` and friends,
which require that parameter since the number of elements of the point
array would otherwise be unknown.  Typical usages of `imagepolygon()`,
`imageopenpolygon()` and `imagefilledpolygon()` pass `count($points)/2`
or hard-code this value as literal.  Since explicitly specifying this
parameter is annoying and error-prone, we offer the possibility to omit
it, in which case the `$points` array must have an even number of
elements, and the number of points is calculated as `count($points)/2`.

We deprecate explicitly passing the `$num_points` parameter, but keep
the sloppy behavior of the functions in this case (for instance, having
an odd number of elements in `$points`).
@KalleZ
Copy link
Member

KalleZ commented Nov 2, 2019

I think this is a good change, having worked heavily with the GD API myself I always wondered why this was exposed in this way to userland, it is a thing we shouldn't burden userland with as we can easily calculate it ourselves.

@@ -199,11 +199,11 @@ function imagecolortransparent(GdImage $im, int $col = UNKNOWN): ?int {}

function imageinterlace(GdImage $im, int $interlace = UNKNOWN): ?int {}

function imagepolygon(GdImage $im, array $points, int $num_pos, int $col): bool {}
function imagepolygon(GdImage $im, array $points, int $num_points, int $col = UNKNOWN): bool {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function imagepolygon(GdImage $im, array $points, int $num_points, int $col = UNKNOWN): bool {}
function imagepolygon(GdImage $im, array $points, int $num_points_or_col, int $col = UNKNOWN): bool {}

Maybe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's definitely more correct for reflection, but might be confusing wrt. the deprecation warning ("the $num_points parameter is deprecated"). However, having an optional parameter in the middle of the parameter list is confusing anyway, but as it would only be temporary, guess it's okay.

@nikic
Copy link
Member

nikic commented Nov 7, 2019

My only concern here would be that this both introduces the new signature and deprecates the old one in the same version. I'd generally prefer it if the new form is introduced first and the deprecation happens later.

@cmb69
Copy link
Member Author

cmb69 commented Nov 14, 2019

I'm fine with postponing the deprecation (we should not forget about it, though).

Anyhow, how to proceed here? Discussion on internals?

Copy link
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, don't think we need extra discussion on this.

@cmb69
Copy link
Member Author

cmb69 commented Nov 15, 2019

Fine, thanks! Applied as 2de79f0.

@cmb69 cmb69 closed this Nov 15, 2019
@cmb69 cmb69 deleted the imagepolygon-numpoints branch November 15, 2019 08:42
@carusogabriel carusogabriel added this to the PHP 8.0 milestone May 29, 2020
php-pulls pushed a commit to php/doc-en that referenced this pull request Dec 19, 2020
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.

4 participants