Skip to content

Zend: add const qualifiers to the majority of compare functions#21304

Merged
Girgias merged 1 commit intophp:masterfrom
Girgias:const-cmp
Mar 19, 2026
Merged

Zend: add const qualifiers to the majority of compare functions#21304
Girgias merged 1 commit intophp:masterfrom
Girgias:const-cmp

Conversation

@Girgias
Copy link
Member

@Girgias Girgias commented Feb 26, 2026

This sadly does not include zend_compare() and functions relying on it due to 2 reasons:

  • The compare object handler doesn't take const pointers
  • The cast object handler (used for comparisons against other types) doesn't take const pointers

This sadly does not include zend_compare() and functions relying on it due to 2 reasons:

- The compare object handler doesn't take const pointers
- The cast object handler (used for comparisons against other types) doesn't take const pointers
@Girgias Girgias marked this pull request as ready for review February 26, 2026 16:38
@Girgias Girgias requested a review from dstogov as a code owner February 26, 2026 16:38
@Girgias Girgias requested a review from TimWolla February 26, 2026 16:38
@TimWolla
Copy link
Member

TimWolla commented Mar 1, 2026

  • The compare object handler doesn't take const pointers

  • The cast object handler (used for comparisons against other types) doesn't take const pointers

Can this be changed or are there implementations that require the parameter to be non-const? Fixing this in external extensions should be a simple #if.

@Girgias
Copy link
Member Author

Girgias commented Mar 1, 2026

  • The compare object handler doesn't take const pointers
  • The cast object handler (used for comparisons against other types) doesn't take const pointers

Can this be changed or are there implementations that require the parameter to be non-const? Fixing this in external extensions should be a simple #if.

The default compare hook (zend_std_compare_objects()) relies on zend_compare(), and adds recursion protections to OP1 so it seems difficult to make the parameters const.

@Girgias Girgias merged commit 38cbbee into php:master Mar 19, 2026
18 checks passed
@Girgias Girgias deleted the const-cmp branch March 19, 2026 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants