php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80336 Fatal error: Uncaught ValueError: strrpos(): Argument #3 ($offset) must be con
Submitted: 2020-11-08 12:56 UTC Modified: 2020-11-08 17:58 UTC
From: info at backups dot nl Assigned: cmb (profile)
Status: Not a bug Package: Strings related
PHP Version: 8.0.0RC3 OS: Ubunutom 20.04
Private report: No CVE-ID: None
 [2020-11-08 12:56 UTC] info at backups dot nl
Description:
------------
Hi

I get this fatal error in php 8.0 rc3

Fatal Uncaught ValueError: strrpos(): Argument #3 ($offset) must be contained in argument #1

Why do i get this error on this code.  It is exactly as the php documentation describes to use it.

$pos = strrpos($url, '.', -1);

Please advice.

Test script:
---------------
$url='https://myserver.com';
$pos = strrpos($url, '.', -1);


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-11-08 13:26 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2020-11-08 13:26 UTC] cmb@php.net
Are you absolutely sure that $url contains a non-empty value?
See <https://3v4l.org/YXmj3>.
 [2020-11-08 13:31 UTC] info at backups dot nl
-Status: Feedback +Status: Assigned
 [2020-11-08 13:31 UTC] info at backups dot nl
i will add a check to test the value of $url being empty.

Thanks for the hint.
 [2020-11-08 15:53 UTC] cmb@php.net
-Status: Assigned +Status: Not a bug -Package: Testing related +Package: Strings related
 [2020-11-08 15:53 UTC] cmb@php.net
Fine.  I'm closing this ticket; please re-open if there is
actually an issue with a non-empty string.
 [2020-11-08 17:30 UTC] info at backups dot nl
Hi

I must say i am not pleased with this change. Because now we have to check by a if statement if the $haystack NOT is empty before calling any strpos or strrpos or any function that uses a $haystack=false parameter.


The php function should do this and just return false not the ones calling the function.

This requires a lot of code changes and makes things slower again as we most of the time don not know the value of the $haystack.
 [2020-11-08 17:35 UTC] rtrtrtrtrt at dfdfdfdf dot dfd
> This requires a lot of code changes and makes things 
> slower again as we most of the time don not know the 
> value of the $haystack

this is *not* true

if/empty are language constructs while strrpos() is an expesnive function call
 [2020-11-08 17:58 UTC] cmb@php.net
-Block user comment: No +Block user comment: Yes
 [2020-11-08 17:58 UTC] cmb@php.net
> I must say i am not pleased with this change.

Then consider to raise that on the internals mailing list[1].
This bug tracker is not the appropriate place for *discussions*.

[1] <https://www.php.net/mailing-lists.php#internals>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Oct 09 14:01:27 2024 UTC