Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strcmp() returns other values than -1, 0, 1 #17119

Closed
ohyeaah opened this issue Dec 11, 2024 · 1 comment
Closed

strcmp() returns other values than -1, 0, 1 #17119

ohyeaah opened this issue Dec 11, 2024 · 1 comment

Comments

@ohyeaah
Copy link

ohyeaah commented Dec 11, 2024

Description

In the strcmp() doc it says:

8.2.0 This function now returns -1 or 1, where it previously returned a negative or positive number.

However I the following code:

<?php echo strcmp("3", "1")."\n";

Resulted in this output:

2

But I expected this output instead:

1

The same problem exists for strncmp() and strncasecmp().

A fix is to change this line in zend_binary_strcmp() and zend_binary_strncmp() in zend_operators.c:

return retval;

to

return retval<0?-1:1;

PHP Version

PHP 8.4.1

Operating System

Debian bookworm

@cmb69
Copy link
Member

cmb69 commented Dec 11, 2024

That's a doc bug, see php/doc-en#3629.

@cmb69 cmb69 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants