[php-src] Issue #11562: strpos strange behavior when accessing $_SERVER(?)
| From: | osasson | Date: | Thu, 29 Jun 2023 20:06:05 +0000 |
| Subject: | [php-src] Issue #11562: strpos strange behavior when accessing $_SERVER(?) | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-244837@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/11562
Author: osasson
### Description
The following code:
```php
<?php
$domain = $_SERVER['HTTP_ORIGIN'];
// uncommenting one of the lines below and it works, but of course not the desired behavior
// $domain = 'http://mysite';
// print_r(666);
$p1 = strpos($domain, '://') + 3;
// the line below is causing the problem although when dumping $p1 and $domain it says $p1 is 7 and
$domain length is greater than 7. When dumping, like when using print_r, the error is not thrown.
$p2 = strpos($domain, ':', $p1);
```
Resulted in this output:
```
Fatal error: Uncaught ValueError: strpos(): Argument #3 ($offset) must be contained in argument #1
($haystack)
```
But I expected this output instead:
```
No Error since the
```
### PHP Version
PHP 8.2.4
### Operating System
Windows 10