Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58781 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 34868 invoked from network); 8 Mar 2012 12:38:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Mar 2012 12:38:35 -0000 Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.170 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.216.170 mail-qy0-f170.google.com Received: from [209.85.216.170] ([209.85.216.170:51129] helo=mail-qy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 29/46-00152-B48A85F4 for ; Thu, 08 Mar 2012 07:38:35 -0500 Received: by qcmt36 with SMTP id t36so318642qcm.29 for ; Thu, 08 Mar 2012 04:38:32 -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=5HSyvdCnafSbkNu2z7aMBkGHxOtu9nyh6mXSoCFcQ24=; b=cRqkgFAYPrMktLtttbTLirehXjV5pePDY44MkD4znpGfHuzefFXCcg7OhEBSJGq9Tw Tc3qbvhKGTjuXe9j+HsBSSzIEDDyKGG+iQA4wI9FHsPuX7mE9JM2oWjMWQomQB6m2ChV 3YdKS1b9k4dav7bhb2LUGMInG/zOyiwawHLTcDJm9nw9msdI9ge22bhbiCvwthW0sBkQ fd6BC6TcwtEO8sjFEO3+TwsotSr616qM69IKWJLrwPRDTO2KLvUlSwHEM8OeIfzPi2qs e76GFsrtDxAA+YEPLFNn4rJj514Z2yK+0e8uJ+0azqHlB/jd9HNweYK7cUQn/3ULAL9I z9Xg== MIME-Version: 1.0 Received: by 10.224.205.130 with SMTP id fq2mr1922018qab.53.1331210312924; Thu, 08 Mar 2012 04:38:32 -0800 (PST) Received: by 10.229.49.74 with HTTP; Thu, 8 Mar 2012 04:38:32 -0800 (PST) In-Reply-To: References: <52.38.15021.3A1E65F4@pb1.pair.com> <4F570EBB.6030103@sugarcrm.com> <60744d7ea642fe03c7110502a3f4276a@mohiva.com> Date: Thu, 8 Mar 2012 07:38:32 -0500 Message-ID: To: Ferenc Kovacs Cc: Arvids Godjuks , Simon Schick , internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] Scalar Type Hinting From: ircmaxell@gmail.com (Anthony Ferrara) > AFAIR Gustavo, Anthony and Nikic discussed on IRC, that maybe the best > solution for scalar type hints would be the unification of the scalar type > hints with the current implementation of zend_parse_parameters. Yeah, that's basically what we were discussing. However, there's one significant issue that I personally have to doing that. in ZPP, if you have a parameter that expects an array, and pass it an int, a warning is raised. But then the main body of the function is skipped (the function isn't executed) and the control is passed back to the calling code. To me, that's not right at all. That basically forces all code to use boolean return error checking. Even if you wanted to use exceptions, you'd still need to wrap the calling code in an if() statement to see if a parameter errored. To me, that makes a *direct* port of zpp a no-go for userland code. Sure, it would be consistent, but it would also lead to some very hard-to-read code if you wanted to make it robust: try { if (!foo($bar)) { return false; } } catch (FooException $e) { // We want to ignore it, because we're maintaining the abstraction and can fix it bar(); return false; } return true; All that code, just to make a robust function call. Not good in my book. > the built in php functions are "enforcing" the function signature via > parsing the parameters through this call. > so for example the above mentioned substr signature is substr ( string > $string , int $start [, int $length ] ) > substr("foobar", "123"); // works like a charm > substr("foobar", 1.5); // works, no warning/notice, although we lose > precision here, > substr("foobar", "123 asd"); // Notice: A non well formed numeric value > encountered > substr("foo", "bar"); // Warning: substr() expects parameter 2 to be long, > string given > > so if we would implement the scalar typehints in a way to map the signature > types to the zpp call, then that would mean that the scalar hints are > consistent across the built-in functions, the documentation, and the > dynamic nature of the language(as one could argue that the current/future > implementation of zend_parse_parameters is in line with the dynamic > casting/type juggling nature of php. What I do like, is the rules for error or no error. How it determines if a zval can be passed to a hint of integer. And I also like that it casts if those rules pass... However, I think the errors that it throws are far too kind, and can be quite confusing and lead to difficult to defend code (meaning that you need 10 or 15 lines of code to defensively call a piece of code). Instead, I'd much prefer the error level be raised to E_RECOVERABLE_ERROR, or throw an exception on those typing errors. At least in user type hints, and preferably in ZPP as well. If the function is not going to be executed, it should raise a much more substantial error... Otherwise *that* is going to be more confusing than anything else IMHO... > just my 2cents Thanks for the reply! Anthony