Php optional parameters without if

Hello,

I’ve been wondering if its possible to write the following ugly piece of code into something more decent-readable:

function get_items($offset = 0, $limit = 0) {
	$items = ($limit !== 0) ? array_slice($this->items, $offset, $limit) : array_slice($this->items, $offset);
}

It it possible to have one array_slice function call and only pass $limit on certain condition?

Thanks for help.

I haven’t tested it but this should work


function get_items($offset = 0, $limit = 0) {
	$items = array_slice($this->items, $offset, ($limit !== 0 ? $limit : null);
}