Skip to content

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

@ohyeaah

Description

@ohyeaah

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions