Describe the bug
I think there is a problem in the way that some methods are handling segments right now.
Here is an example:
$uri = new \CodeIgniter\HTTP\URI('http://something.com/hello/there');
// will return ['hello', 'there']d($uri->getSegments());
// will return 'hello' - okd($uri->getSegment(1));
// will return 'there' - okd($uri->getSegment(2));
// will return '' - why? it's not thered($uri->getSegment(3));
// will throw an exception - ok// not really easy to work with but this is a different storyd($uri->getSegment(4));Here we go with a really strange part:
$uri = new \CodeIgniter\HTTP\URI('http://something.com/hello/there');
// will return '' - why? it's not thered($uri->getSegment(3));
// will NOT throw an exception (even if segment 3 is not set)d($uri->setSegment(4, 'honey'));
// will return '' - that's surprising considering no error when// we set it a line befored($uri->getSegment(4));
// will return 'honey'd($uri->getSegment(3));Actually I don't think it's very complicated to fix, but the main problem are BC changes. People can already rely on the empty string that is returned in some cases. So the question is how should it be handled.
Also working with getSegment() and throwing an exception when segment is not there is not very easy to work with. So it would be good to have something to surpass this without the need of catching the exception every time. One idea was proposed here: #2952 → #3005
CodeIgniter 4 version
All versions
Affected module(s)
URI class
Expected behavior
$uri = new \CodeIgniter\HTTP\URI('http://something.com/hello/there');
// should throw an exceptiond($uri->getSegment(3));$uri = new \CodeIgniter\HTTP\URI('http://something.com/hello/there');
// should throw an exceptiond($uri->getSegment(3));
// should throw an exceptiond($uri->setSegment(4, 'honey'));
// should throw an exceptiond($uri->getSegment(4));
Describe the bug
I think there is a problem in the way that some methods are handling segments right now.
Here is an example:
Here we go with a really strange part:
Actually I don't think it's very complicated to fix, but the main problem are BC changes. People can already rely on the empty string that is returned in some cases. So the question is how should it be handled.
Also working with
getSegment()and throwing an exception when segment is not there is not very easy to work with. So it would be good to have something to surpass this without the need of catching the exception every time. One idea was proposed here: #2952 → #3005CodeIgniter 4 version
All versions
Affected module(s)
URI class
Expected behavior