Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84972 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50619 invoked from network); 16 Mar 2015 02:36:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Mar 2015 02:36:29 -0000 Authentication-Results: pb1.pair.com header.from=dennis@birkholz.biz; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=dennis@birkholz.biz; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain birkholz.biz does not designate 144.76.185.252 as permitted sender) X-PHP-List-Original-Sender: dennis@birkholz.biz X-Host-Fingerprint: 144.76.185.252 mx01.nexxes.net Received: from [144.76.185.252] ([144.76.185.252:41780] helo=mx01.nexxes.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F6/7E-06614-AA146055 for ; Sun, 15 Mar 2015 21:36:28 -0500 Received: from [137.226.183.192] (ip3192.saw.rwth-aachen.de [137.226.183.192]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: db220660-p0g-1@packages.nexxes.net) by mx01.nexxes.net (Postfix) with ESMTPSA id 05681482440 for ; Mon, 16 Mar 2015 03:36:23 +0100 (CET) Message-ID: <550641A7.7070809@birkholz.biz> Date: Mon, 16 Mar 2015 03:36:23 +0100 Reply-To: internals@lists.php.net User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC][Status] Scalar Type Declarations Voting Date Change From: dennis@birkholz.biz (Dennis Birkholz) Hi all, Am 16.03.2015 um 03:16 schrieb Yasuo Ohgaki: > This code is an example that I posted in other thread. > > e.g. > function check_num_range(int $num) { if ($num < 0 || $num > 100) > trigger_error('Invalid range'); } > // Somewhere far from function definition. > $num = $GET['num']; > // Somewhere far from $num definition. > check_num_range($num); // Trying to check validity, int and range. > echo 'You have '.$num. ' now
'; // But $num could have any string. > // > "check_num_range((int)$num)" wouldn't help also. > > Simple cast hides bugs, not eliminates type bugs. > This is just an example and there are many cases that cast hides bugs in > real world codes. please, if check_num_range() would be a build-in function, the outcome would be exactly the same. If $num contains something like "100 dogs", you get a notice: http://3v4l.org/fnuAc/rfc#tabs If $num contains rubbish, you get a catchable fatal error: http://3v4l.org/UStfP/rfc#tabs If you handle notices like errors, everything is fine for you. (And you should do that!) If you bring up an example to prove a point, please test it beforehand. If you have strict mode not enabled, there is exactly no incentive for you to always use casts. Greets Dennis