Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58992 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77570 invoked from network); 18 Mar 2012 05:46:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Mar 2012 05:46:40 -0000 Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.170 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 209.85.161.170 mail-gx0-f170.google.com Received: from [209.85.161.170] ([209.85.161.170:37338] helo=mail-gx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 39/D0-63274-FB6756F4 for ; Sun, 18 Mar 2012 00:46:39 -0500 Received: by ggmb2 with SMTP id b2so5681582ggm.29 for ; Sat, 17 Mar 2012 22:46:36 -0700 (PDT) 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; bh=IexBfyD6YEr0sIGbJUvMLmD0tgDs5H3TtbcjXhmXRww=; b=0/UINn5U3XkRtF8bv84VSFE1zyRPxH8Kf08kRMM7fYihovJhglMEfnC/qKCi/GNtc6 s7cxpWrUdBZfNCdq/wUKUfgQFaR5nmK9lgK63veq/0Vfmf1Z1o3EE0V0N9kneblw748R twm2a679+Zu6k6f4fvGvSxo5flj2vdBS/CiNMJWLivxbUtOBsVOmHZUtzU9C64bcpC5u aExJVdo9KNc6uAC6gPhGgxrzjdQz5p+A8EyTcnjn4gIqzYsHc1Pl4idh4kmSTZ3LE92E CDFIUTfrW/Q2AC7gEk8hwcJdPTHrVdMiYuUDTmGdCHbt1FwyUsoKnAa82K2qbKljXwUE reTQ== Received: by 10.236.156.34 with SMTP id l22mr7970141yhk.118.1332049596297; Sat, 17 Mar 2012 22:46:36 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.109.4 with HTTP; Sat, 17 Mar 2012 22:46:15 -0700 (PDT) In-Reply-To: References: Date: Sun, 18 Mar 2012 06:46:15 +0100 Message-ID: To: John Crenshaw Cc: Simon Schick , PHP Internals List Content-Type: multipart/alternative; boundary=20cf303f6d2202b0e304bb7df78a Subject: Re: [PHP-DEV] Scalar-type-hinting - which way is the best to go? From: ocramius@gmail.com (Marco Pivetta) --20cf303f6d2202b0e304bb7df78a Content-Type: text/plain; charset=UTF-8 Thank you for clarifying some things :) > 4. Strict weak type hinting: > > This realm is the most likely to succeed because the core already does > something like this for internal functions (via zend_parse_parameters). > This balances utility (enforcing the type) with fundamental language design > principles (juggling). You need to understand the fundamental language > principles to understand why any solution MUST lie somewhere in this realm. > Remember that: > 1.2 === "12"; > "2"+"2" === 4; > substr(12345, "2") === "345"; > > This type juggling affects the language in all sorts of ways. For example, > PHP uses '.' for concatenation (not '+' like most similar languages) which > ensures that there is no ambiguity as to whether you are operating against > the integer value or the string value. PHP is designed so that you > generally don't have to care whether a value is ACTUALLY an integer or a > string internally, it will be treated as whatever type you use it as. In > PHP int(2), float(2.0), and string("2") can generally be used completely > interchangeably with no variation in results whatsoever. When core devs say > that "strict typing would make it not PHP anymore", this is what they mean; > it would badly violate this core concept. If you want scalar typing, you > need a solution that embraces this fundamental design principle. > > Yeah, I don't want to start a discussion on that now nor start a (probably already repeated) war on it, but I think those principles are dead since very long time... > > 5. Boxing based type hinting: > > This is a hack that's been proposed before, but you don't need to look > very far to see why this ultimately breaks down badly. Even aggressive > casting additions to the language would not make this work particularly > well. Anyone who's ever tried to create a class wrapper for a scalar in C++ > (which probably includes the core devs) is not likely to be down with this > idea. > > That's not about working with scalar wrappers (which, anyway, would be very useful in Doctrine). It is about casting any object to array... `((int) $dbTableGateway)` could implicitly cause an sql `COUNT` query and stuff like that :) Maybe I'm too java-ish, but those look like good improvements to me :) --20cf303f6d2202b0e304bb7df78a--