Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58623 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77438 invoked from network); 5 Mar 2012 21:42:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Mar 2012 21:42:59 -0000 Authentication-Results: pb1.pair.com smtp.mail=admacedo@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=admacedo@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.42 as permitted sender) X-PHP-List-Original-Sender: admacedo@gmail.com X-Host-Fingerprint: 209.85.215.42 mail-lpp01m010-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:50786] helo=mail-lpp01m010-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 77/9F-35539-063355F4 for ; Mon, 05 Mar 2012 16:42:58 -0500 Received: by lahl5 with SMTP id l5so5694154lah.29 for ; Mon, 05 Mar 2012 13:42:53 -0800 (PST) Received-SPF: pass (google.com: domain of admacedo@gmail.com designates 10.112.25.40 as permitted sender) client-ip=10.112.25.40; Authentication-Results: mr.google.com; spf=pass (google.com: domain of admacedo@gmail.com designates 10.112.25.40 as permitted sender) smtp.mail=admacedo@gmail.com; dkim=pass header.i=admacedo@gmail.com Received: from mr.google.com ([10.112.25.40]) by 10.112.25.40 with SMTP id z8mr10021866lbf.11.1330983773423 (num_hops = 1); Mon, 05 Mar 2012 13:42:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=M3ygan5cTjBjhONFjswP7b5OYmQ6lzwULk1miRUaVzw=; b=P5bPMqedh5KdF/YzxysVsuicHlLUYBId2uOHibgYzRaZgJf/Fj0i8N1VlpD2oocu9x FAoL44dN4IwTK7WEdLR0RT0Nfz0tzbvlimdCyDUUL4H/4OfyRKkoCiRORxKvN6Hg7kuH OrUStAQSUkRhyUze/ZkUjmO8cLnOAuAqehYAs7XEJESpHZvYS3QLugYnEqalh8zIJYDL jpMl9EP6ylL+RKPjVNIRGz+gE5bitYy7i+oXNcDF7n6D+4i5KzMWTH8K5uUAODKzeIYo S+cBIKxR4QSlaAlHb8W6sKzr50e9Z2yvp8rm0PPhGx8Z6t+A3gFcuM85HN7jC6r2EIDB hChQ== Received: by 10.112.25.40 with SMTP id z8mr8156835lbf.11.1330983773242; Mon, 05 Mar 2012 13:42:53 -0800 (PST) MIME-Version: 1.0 Received: by 10.112.36.234 with HTTP; Mon, 5 Mar 2012 13:42:13 -0800 (PST) In-Reply-To: References: Date: Mon, 5 Mar 2012 21:42:13 +0000 Message-ID: To: Lazare Inepologlou Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [POC Patch] Scalar Type Hinting/Casting - Proof Of Concept From: admacedo@gmail.com (Daniel Macedo) Sorry, I used unset in the same way type casting works, not as in unset() ... Common gotcha: http://php.net/unset#example-4824 Here's how the manual refers to it: http://php.net/type-juggling (int), (integer) - cast to integer (bool), (boolean) - cast to boolean (float), (double), (real) - cast to float (string) - cast to string (array) - cast to array (object) - cast to object (unset) - cast to NULL (PHP 5) I understood what you meant but I'd rather have it be more verbose but more clear as well. I read your idea, as "Cast to int, or accept NULL" I rather use/read that as (int unset) rather than (int?) > =A0> BTW: Order would equal what is type casted OR simply accepted! > > Do you have any examples where this could be useful? The same example you gave of data that comes from a database NULL would be retained, else it's type casted to int. // Cast to int, accept null (int unset) 13 // 13 (int unset) '' // 0 (int unset) 0 // 0 (int unset) NULL // NULL (int unset) '342.3Test' // 342 My view is, if you use the naming as it's currently used in type casting, you also get additional functionality: // Cast to string, accept bool (string bool) 'test' // 'test' (string bool) 123 // '123' (string bool) TRUE // TRUE (string bool) FALSE // FALSE (string bool) NULL // '' // Cast to string, accept array (string array) 'test' // 'test' (string array) 123 // '123' (string array) TRUE // '1' (string array) array(1, 2, 3) // array(3) { [0]=3D> int(1) [1]=3D> int(2) [2]=3D> int(3) } I find this way more useful/complete/readable than what you proposed. Best regards, ~ Daniel Macedo