Hello list,

I found this RFC, describing a feature I wanted for a long time:
https://wiki.php.net/rfc/list_default_value
https://marc.info/?l=php-internals&m=144707619509724

(I don't know how to correctly reply to old emails that are not in my
inbox, sorry for that. I don't like mailing lists.)

I regularly want this kind of feature when unpacking a string with explode():

list($prefix, $suffix = NULL) = explode(':', $string);
if (NULL !== $suffix) {
  ...
}

This is for situations where a string is coming from somewhere, we
hope it has the format "aaa:bbb", but we cannot be sure.

Sometimes I use a workaround like this:

list($prefix, $suffix) = explode(':', $string . ':');
if ('' !== $suffix) {
  ...
}
Which works, but means a new string will be allocated in memory.

I find the list() with default values to be a decent and
understandable language feature.

-- Andreas

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to