[php-src] Issue #22420: `json_encode()` errors don't clear the error position

[email protected] (TimWolla) Wed, 24 Jun 2026 08:56:55 +0000
Newsgroups php.bugs
Message-ID <[email protected]>
Issue: https://github.com/php/php-src/issues/22420
Author: TimWolla

### Description

The following code:

```php
<?php

var_dump(json_decode('{132'));
var_dump(json_last_error_msg());
var_dump(json_encode("\xFE\xD0"));
var_dump(json_last_error_msg());
```

Resulted in this output:
```
NULL
string(30) "Syntax error near location 1:2"
bool(false)
string(74) "Malformed UTF-8 characters, possibly incorrectly encoded near location 1:2"
```

But I expected this output instead:
```
NULL
string(30) "Syntax error near location 1:2"
bool(false)
string(56) "Malformed UTF-8 characters, possibly incorrectly encoded"
```


### PHP Version

```plain
PHP 8.6.0-dev (cli) (built: Jun 24 2026 10:30:47) (NTS DEBUG)
Copyright © The PHP Group and Contributors
Zend Engine v4.6.0-dev, Copyright © Zend by Perforce
    with Zend OPcache v8.6.0-dev, Copyright ©, by Zend by Perforce
```

### Operating System

_No response_