Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83035 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59178 invoked from network); 18 Feb 2015 09:14:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Feb 2015 09:14:08 -0000 Authentication-Results: pb1.pair.com header.from=narf@devilix.net; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=narf@devilix.net; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain devilix.net designates 209.85.214.170 as permitted sender) X-PHP-List-Original-Sender: narf@devilix.net X-Host-Fingerprint: 209.85.214.170 mail-ob0-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:59432] helo=mail-ob0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6D/46-18888-ED754E45 for ; Wed, 18 Feb 2015 04:14:08 -0500 Received: by mail-ob0-f170.google.com with SMTP id va2so62903612obc.1 for ; Wed, 18 Feb 2015 01:14:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=devilix.net; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=DQXPP8HPImu0+t7Gnueh2Q6i+bE4UhKpMVgtI+AYRkI=; b=paXEkIEwBle/ARUl6rEauCdQ5YdPt8dRGJ/haLxZhl0xsk9vvwxiH71Lp/aTD08H9q dP+JASc7KkjnalpCY+Nm4xoBIcSeVBJBZ4ljTo3dzcibouLlT70M+6U5G7A8Kwvg5wPD zPMLyuaK+dF0omByMTVnAm63nwxj19X9bHXmM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=DQXPP8HPImu0+t7Gnueh2Q6i+bE4UhKpMVgtI+AYRkI=; b=eveEdSpCGUQqY0t4wFocN5mufVSsnVcxsBlAf8KgxtzLFIcK71YDm3IPS9TxgXwvcR AC9fWdolXZJ5tDHBjVfiMpA+bjT5jGjky/49oG16jyWJByvoQMWUANGJqWnY1xytagTP kHOGKDUmGUW8p2b3OZPjhyYK7Mni8OAuq7bzscaqqBL2mBP0J6d7CMIscgJxmd0xOhky HaR2WxS6+R8M9BUwUsTrkWQT+mPc3s5EbETTtrHCfxFlTsLgvdTrmJMa8zANVdcvqm9k mF/FteWfhUkYUsVh1GBh4BYIR9EfEVO9S6fihdkH+PcpDI7kPp4iBc5AQA4YtBa+hznp VNCQ== X-Gm-Message-State: ALoCoQnlklHo/H4tNN+1CzWAsD8gCnSox0OkmZBDNknAwAva6XNogheOxfYSFHoHdtxrJir1tqMN MIME-Version: 1.0 X-Received: by 10.60.93.5 with SMTP id cq5mr2757906oeb.3.1424250844381; Wed, 18 Feb 2015 01:14:04 -0800 (PST) Received: by 10.202.214.205 with HTTP; Wed, 18 Feb 2015 01:14:04 -0800 (PST) In-Reply-To: <2f99c47df51fa6c73131032ec50fade0@mail.gmail.com> References: <54E3E27B.2010903@lerdorf.com> <2f99c47df51fa6c73131032ec50fade0@mail.gmail.com> Date: Wed, 18 Feb 2015 11:14:04 +0200 Message-ID: To: Zeev Suraski Cc: Nikita Popov , Rasmus Lerdorf , Sara Golemon , PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Scalar Type Hints v0.4 From: narf@devilix.net (Andrey Andreev) Hi, On Wed, Feb 18, 2015 at 9:00 AM, Zeev Suraski wrote: >> -----Original Message----- >> From: Nikita Popov [mailto:nikita.ppv@gmail.com] >> Sent: Wednesday, February 18, 2015 3:06 AM >> To: Rasmus Lerdorf >> Cc: Sara Golemon; PHP internals >> Subject: Re: [PHP-DEV] Scalar Type Hints v0.4 >> >> The inability to implicitly cast "123" to int is pretty much the KEY >> distinction >> between weak and strict scalar typehints (those pesky value-dependent type >> checks). If the strict typing mode doesn't offer this, what's the point at >> all? > > I am wondering what the point is indeed with preventing "123" to 123. So > far, all the concrete use cases people brought up had to do with "Apple" or > "100 dogs", but nobody ever seems to be able to explain why converting "123" > to 123 is likely to be a problem real world. Is it really just static > analyzers? > I too am curious about the potential issue with "123" to 123 specifically, although it could be seen as a subset of another problem that is solved with strict hints - numeric-character string identifiers being erroneously treated as integers. That is especially bad when such identifiers are in fact generated as integers first so that they are incremental, but the program/database/business logic requires them to be fixed-length strings and/or in hexadecimal format. In such cases, even silently discarding leading zeros can prove to be problematic, while in the case of hexadecimal representations you'd need more than 10 data samples to notice the problem if you don't use a strict hint. Obviously, that would be solved with automated testing, but unfortunately even code with high test coverage % often lacks depth in its test cases. I believe reduced amount of necessary unit tests was already brought up as an advantage of strict type hints, so I'm just explaining one such use case in detail here. Cheers, Andrey.