Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34399 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 6896 invoked by uid 1010); 4 Jan 2008 10:47:52 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 6881 invoked from network); 4 Jan 2008 10:47:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Jan 2008 10:47:52 -0000 Authentication-Results: pb1.pair.com smtp.mail=rquadling@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rquadling@googlemail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.146.180 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: rquadling@googlemail.com X-Host-Fingerprint: 209.85.146.180 wa-out-1112.google.com Received: from [209.85.146.180] ([209.85.146.180:25264] helo=wa-out-1112.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A4/E6-20810-3DE0E774 for ; Fri, 04 Jan 2008 05:47:51 -0500 Received: by wa-out-1112.google.com with SMTP id l24so12042285waf.17 for ; Fri, 04 Jan 2008 02:47:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; bh=IkKaP6yQTYxc02D2mfIN06n4DDwYjtJM93YEMIYZIAk=; b=kO0k5TN/tkJTdskn5Pfw3/uJZ1YVoi1e5PNeDIMA+iAw5GaotVICeG95imRtdeyogwyo/duZBuVrIkWzHKdvJ3aIXQcZSGW88gaHx06XeP8UzGJFTw02YYnhWSNWOk/m5J25Q4Mr9A+r3gNx5QoqcBbr/AcKOJ8D97UNglsAU8g= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=kveD/poa2U4vyNsRZQdBwUkvD4iVW3MUGuOOrjMvrd6xVLIjFqYxD0lNVQEmCv+jyTS1PuU5ydScon3WXqQve1iaE/RvmwD9cKVNcLXldXlVfHhozi62pzuEbKlOS+D4loJ3ceZpBeAGS78ewNu5jIvUPe2FEkc/jkvA9U2f0zk= Received: by 10.114.107.19 with SMTP id f19mr16365620wac.113.1199443663226; Fri, 04 Jan 2008 02:47:43 -0800 (PST) Received: by 10.114.210.8 with HTTP; Fri, 4 Jan 2008 02:47:43 -0800 (PST) Message-ID: <10845a340801040247v48d4cfe9t8bc226af4a7b0b5d@mail.gmail.com> Date: Fri, 4 Jan 2008 10:47:43 +0000 Reply-To: RQuadling@GoogleMail.com To: "internals Mailing List" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline Subject: "Loose lips sink ships" or who REALLY uses loosely typed code? From: rquadling@googlemail.com ("Richard Quadling") Hi. I've been trying to get a sensible understanding of the for's and against's of the optional scalar type hinting question. With that I have a few points and a question. 1 - In the main, PHP is used to create web pages and to deal with data coming from the user. 2 - In the main, the data coming in is strings. 3 - In the main, the data must be validated and often this involves converting the submitted strings into another type (date, integer, boolean, float, maybe arrays of these) as casting the data to another type is the simplest way to guarantee that the string holding a number for use in, say a DB query, doesn't contain nasties to force the query to misbehave. I would say, that in the main, most data, once received, remains typed. Whilst the above is not how everyone will work, I hope you all agree that this is a strong general case. Internally generated data is also normally always typed. You add integers to produce integers. You test boolean variables. About the only time I __RELY__ on the auto conversion is for string concatenation. This is immensely useful (except booleans don't convert to True/False which would be GREAT!!!!) If I want to set a boolean, I set it to True or False. Not "0", 0, "1", Null, etc - which can all be converted to a boolean sure, but for reading the code, seeing true and false is quite clearly showing that this is a boolean test and not an integer test. In the comments that have been raised about scalar type hinting, those against say it moves you towards a strictly typed language. I would argue that whilst PHP is not a strictly typed language, in the main it is used as such and that __OPTIONAL__ scalar type hinting has a benefit for those that would like to use it. function x([untyped] $m_Mixed, string $s_String, bool $b_Flag) This is understandable and readable. If you try to pass the wrong sort of object or you don't pass an array, the code fails in its way. Increasing the capability of failing (with maybe an option to force conversion of scalar types) would seem to be a suitable way to go. Regards, Richard Quadling. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!"