Re: [RFC][DISCUSSION] Allow default value in list() syntax

From: Date: Thu, 10 Aug 2017 21:21:12 +0000
Subject: Re: [RFC][DISCUSSION] Allow default value in list() syntax
Groups: php.internals 
Request: Send a blank email to internals+get-100172@lists.php.net to get a copy of this message
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

« previous php.internals (#100172) next »