Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78265 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65008 invoked from network); 23 Oct 2014 10:18:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Oct 2014 10:18:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.172 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.172 mail-wi0-f172.google.com Received: from [209.85.212.172] ([209.85.212.172:43492] helo=mail-wi0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BD/A3-41150-FD5D8445 for ; Thu, 23 Oct 2014 06:18:08 -0400 Received: by mail-wi0-f172.google.com with SMTP id bs8so3680026wib.5 for ; Thu, 23 Oct 2014 03:18: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:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=KgorNin5XuAN9Q5b3S4tGjH2/AIo5eqGgRQ07N7OFQs=; b=Z71nShPFXzfSXZIs58WCktIDVQiStnRraLQZ1umbJnBwXakoUVzh82opVu1w3EGKgZ uBYsRj//A8E4LeiuNLACJYdoFjqQqAhVMJ8iz9Sno8Z2XYhNBaM7sHE3d8Pd+hpNGLmo /ib7sM6y867uVjnqyK1Q9FP4pmiTDqp3ETC/iJNNuOWwk9rle+QF/NnhTP0O3QFBLufl g1o/4i2fitjIPXWDh+lS8shM+jjDHUdaFxqnpuPoK6hFKkPK86Ah1KL4fcvkhvzUTUV3 5zBeK9/c6ZxJnD9DMRuCPZTnslfiXnb3tEcc7/XvVqO/9Xr/tVDJmp/G8H4OrN67f8KL 43aQ== X-Received: by 10.194.2.168 with SMTP id 8mr4565409wjv.78.1414059484473; Thu, 23 Oct 2014 03:18:04 -0700 (PDT) Received: from [192.168.0.177] ([62.189.198.114]) by mx.google.com with ESMTPSA id bi7sm2046092wib.17.2014.10.23.03.18.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Oct 2014 03:18:03 -0700 (PDT) Message-ID: <5448D5D7.4010800@gmail.com> Date: Thu, 23 Oct 2014 11:17:59 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: internals@lists.php.net References: <66B7B28C-2651-4A71-AC2A-55D4C7BB3DDC@ajf.me> <5448018E.3090005@mabe.berlin> In-Reply-To: <5448018E.3090005@mabe.berlin> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] Safe Casting Functions From: rowan.collins@gmail.com (Rowan Collins) Marc Bennewitz wrote on 22/10/2014 20:12: > On 22.10.2014 10:37, Bob Weinand wrote: >> I know we have that already discussed a lot now, but I’d like to expose my points on the return value here: >> >> I imagine code like (supposing that we ever will have scalar typehints): >> >> function acceptsInt (int $i = null) { >> if ($i === null) { >> $i = 2 /* default value */; >> } >> /* do something with $i */ >> } > NULL isn't a pointer for a default value - it's simply a type with no > value - no more - no less. > From your example: why do you accept NULL if you need a integer default > value? > > function acceptsInt (int $i = 2) { ... Those are two distinct types of default: - the default value to use when a programmer calls the function with fewer parameters (e.g. acceptsInt()) - the default value to use when a value is provided by the programmer, but turns out to be null at runtime (e.g. acceptsInt($_GET['foo']))