Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62504 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39804 invoked from network); 26 Aug 2012 00:19:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Aug 2012 00:19:10 -0000 Authentication-Results: pb1.pair.com header.from=krebs.seb@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=krebs.seb@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.170 as permitted sender) X-PHP-List-Original-Sender: krebs.seb@gmail.com X-Host-Fingerprint: 74.125.82.170 mail-we0-f170.google.com Received: from [74.125.82.170] ([74.125.82.170:60149] helo=mail-we0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BB/48-06857-C7B69305 for ; Sat, 25 Aug 2012 20:19:10 -0400 Received: by weyr1 with SMTP id r1so1899572wey.29 for ; Sat, 25 Aug 2012 17:19:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=5+AqM90aVPQjsJICBkl65xDI43eCpEJX0c4mNH6AqPg=; b=J54/rBeBwTaqStp8H3vYSEAgrpbDKWQ25fY7S3aldF9el8rLx59Z79ufu5QoqRyO6L u5ihlnRvQNmLYMTYSE0yjRkWrDaq/LHeMO0Iu/uNwDfg+kCsa4nHdPfbR9TCocLBH5g4 /qr4cAlg7sSdNQW+tzsIYE3AbzvLQVT2I7q/qO4jpT1mwcw8s78+cDQ1FLHCJmQ1QmV1 si3l0ZNbv+Yl2wwyy1FEJQ/xB2xFShmGwC9cVopBSJ5bLRkrvzJI2ZYv3bEqTD13tCH3 Soc4Vlo8JUT9957J0mnL2+wbLdMoYL+zLDDpgAHX2mgY/47UMVt/yKa/3Njq5g726nhF HFMw== Received: by 10.216.198.145 with SMTP id v17mr5007064wen.1.1345940344504; Sat, 25 Aug 2012 17:19:04 -0700 (PDT) Received: from [192.168.24.2] (91-66-42-108-dynip.superkabel.de. [91.66.42.108]) by mx.google.com with ESMTPS id o2sm9175253wiz.11.2012.08.25.17.19.03 (version=SSLv3 cipher=OTHER); Sat, 25 Aug 2012 17:19:04 -0700 (PDT) Message-ID: <50396B77.6070202@gmail.com> Date: Sun, 26 Aug 2012 02:19:03 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: Ferenc Kovacs CC: David Muir , PHP internals list References: <502EBAA4.9090007@gmail.com> <50381196.4090606@gmail.com> <5039102F.5010305@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Combined assignment operator for short ternary From: krebs.seb@gmail.com (Sebastian Krebs) Am 26.08.2012 01:57, schrieb Ferenc Kovacs: > > > So you are saying that your (teams) IDE doesn't tell you the method > > signature which contains also the default values? > > I guess that the fact that many of the php core functions have > optional > > arguments and non null defaults must be really a PITA for you. > > I think what he was alluding to is the problem where one changes the > default. > > All usages of the method/function then need to be updated. Using > null today is very much like using the proposed 'default' parameter > skipping RFC. > > > true, using null as a default value for your optional arguments means > that you don't really need the parameter skipping RFC (at least for the > functions that you control) or the named params, because you can pass > null for the in-between optional arguments. > ofc. most modern IDEs also have some kind of refactoring feature, which > would make it easier for you to update the function calls to reflect the > change in the default value, but it would be harder to tell the original > intention ($limit is 30 here, because it was the default and the caller > wanted to set the next optional argument, or $limit is intentionally set > to 30 and the next optional argument also happen to be needed). > thanks for clearing that one up for me. > > Having every optional argument defaulting to null means that it can be > frequent scenario, when you have a variable, which is guaranteed to be > defined, but can be null. > But I still think that it isn't that frequent that you want to keep the > non falsely values or set a default value otherwise. > I mean if you expect a number, then you don't want your passed 0 to be > replaced with the default, or if you expect a string, you don't want "0" > or maybe even "" to be replaced with the default, etc.. > So you couldn't use the ternary assignment for those scenarios. Yes, it doesn't work in this cases, but I must say - I try to avoid optional parameters whereever useful. The caller should be aware of what he is doing. I prefer to define "preferred values" as constants instead, that can be used whereever a preferred behaviour is wanted. - I do't implement very much functions/methods, where (e.g.) 0 is allowed and should _not_ be the default (same for strings and so on), thus '$index = $index ?: 0;' is valid regardless wether $index is 0 or null in the first place. Or if I expect a string the empty string '' is most of the time a special cases (or required). If I expect an object is just obvious, that they can never evaluate to false. I don't think we need argue about this, because this two points are more or less personal preferences/opinions. But this said there are only some few edge cases (for me), where I need to distinguish between '', 0, null, ..., and in this few cases, I can still use the good old `$index = is_null($index) ? 123 : $index;` ;). At the end: It works just great to use null as general-purpose-default. I don't care about a special 'default'-keyword, because in my mind something like that already exists in form of 'null': It's either "the default primitive value", or "no-object" (in case an object was expected, but not required). > > -- > Ferenc Kovács > @Tyr43l - http://tyrael.hu