Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80044 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21110 invoked from network); 1 Jan 2015 13:29:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Jan 2015 13:29:53 -0000 Authentication-Results: pb1.pair.com header.from=nek.dev@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nek.dev@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.180 as permitted sender) X-PHP-List-Original-Sender: nek.dev@gmail.com X-Host-Fingerprint: 209.85.212.180 mail-wi0-f180.google.com Received: from [209.85.212.180] ([209.85.212.180:46434] helo=mail-wi0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 88/D8-60454-FCB45A45 for ; Thu, 01 Jan 2015 08:29:52 -0500 Received: by mail-wi0-f180.google.com with SMTP id n3so26677161wiv.1 for ; Thu, 01 Jan 2015 05:29:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=QiSrE9kdXIyjupuL2dvwws3/kSwQeIEtdxYzEbf4Bno=; b=CQ0Ds87XiyfAQr1rDHkKCfZfv4anshk0ZOJXB0aTebFU+kwrB3alr0pup94tTjz2FR UrngwJywmTGJrIl11syXQMYhL9koZaXtCWAF60WllocpA8D2tCL0EYMBpTOCybvjA22g Pwsp5hStjA8lnWN+EQ2wnZm0gWn7JXS+exHbbd73Ncc/CtnrvQyZrK2xUCIyKWRlRQKy CP0PsQCDPKI2+WVZj8oPdFkyIclPh3ZtlED9fg5txiRhyXmGWNwSL6ufZgFYxuSQsARk 7MI+bWiqjgBWCGgfrjP9804CBei+kkR1cvYobEjv9Q31bl3YV4uwWDQepZqFhvHoq1h6 +urw== MIME-Version: 1.0 X-Received: by 10.180.198.211 with SMTP id je19mr122102276wic.27.1420118986534; Thu, 01 Jan 2015 05:29:46 -0800 (PST) Received: by 10.27.203.70 with HTTP; Thu, 1 Jan 2015 05:29:46 -0800 (PST) In-Reply-To: <16d442a345cf2cbd4faac6d068c57343@mail.gmail.com> References: <41D5BB0B-73AF-488E-968D-90B2878E3178@ajf.me> <16d442a345cf2cbd4faac6d068c57343@mail.gmail.com> Date: Thu, 1 Jan 2015 14:29:46 +0100 Message-ID: To: Zeev Suraski Cc: Andrea Faulds , PHP Internals Content-Type: multipart/alternative; boundary=047d7b62536abb38cc050b97374f Subject: Re: [PHP-DEV] [RFC] Scalar Type Hints From: nek.dev@gmail.com (Maxime Veber) --047d7b62536abb38cc050b97374f Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hello, I was expected an RFC like this in PHP for a while. I'm happy somebody made one, thanks. But something hit me in that. even if you can't give an objet, you can give any scalar type that will be cast. I'm not sure this behavior is very relevant. Actually if I ask for a string, why the user could be specify an int without getting error ? Consider the following PHP 5.6 code: function foo($a) { if (!is_string($a)) { throw new \Exception('You need to give a string'); } } Using your type hinting does not fix the problem of string checking because the value will just be cast if it's an integer. Ofc if the user give an object it's ok. But why not throw a message error in any cases ? I hope i'm clear enough. Thanks for reading and have an happy new year :-) . 2015-01-01 13:41 GMT+01:00 Zeev Suraski : > > -----Original Message----- > > From: Andrea Faulds [mailto:ajf@ajf.me] > > Sent: Wednesday, December 31, 2014 10:28 PM > > To: PHP Internals > > Subject: [PHP-DEV] [RFC] Scalar Type Hints > > > > Good evening, > > > > Parameter type hints for PHP=E2=80=99s scalar types are a long-requeste= d feature > > for > > PHP. Today I am proposing an RFC which is a new attempt to add them to > > the language. It is my hope that we can finally get this done for PHP 7= . > > Andrea, > > > I like this draft too, and that's a first after countless proposals over > the > last decade - so kudos! :) > > My main feedback here are the discrepancies between this RFC's casting > rules > and PHP's current built-in casting rules. Ideally, I'd like those to be > completely identical and not almost-identical. > Since we're talking about v7.0, we do have the option of making changes t= o > PHP's fundamental casting rules where appropriate (e.g. converting an arr= ay > to a string). > But that said, I think the way strings->numbers are handled - where they > accept only numeric strings as it would mean you can't use casting to an > int/float as an ultra-simple way to sanitize untrusted input. I would > change the =E2=80=A0 section from: > > =E2=80=A0Non-numeric strings not accepted. Numeric strings with trailing = characters > are accepted, but produce a notice. > to > =E2=80=A0 Numeric strings with trailing characters and non-numeric string= s are > accepted, but produce a notice. > > - and apply it to both this RFC and the infrastructure convert_to_*(), so > that it applies across the board in PHP. > > Zeev > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --047d7b62536abb38cc050b97374f--