Skip to content

URI::getSegment() returns non-existent segment #7246

@kenjis

Description

@kenjis

CodeIgniter version: 4.3.1

In this sample, there are three URI segments: 1:users, 2:15, 3:profile
But you can get the 4th segment $uri->getSegment(4, 'bar') without Exception.
But $uri->getSegment(5, 'baz') will throw Exception.

// URI = http://example.com/users/15/profile

// will print 'profile'
echo $uri->getSegment(3, 'foo');
// will print 'bar'
echo $uri->getSegment(4, 'bar');
// will throw an exception
echo $uri->getSegment(5, 'baz');
// will print 'baz'
echo $uri->setSilent()->getSegment(5, 'baz');
// will print '' (empty string)
echo $uri->setSilent()->getSegment(5);

https://codeigniter4.github.io/CodeIgniter4/libraries/uri.html#uri-segments

Related: #7233

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions