Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62181 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20726 invoked from network); 15 Aug 2012 10:29:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Aug 2012 10:29:19 -0000 Authentication-Results: pb1.pair.com header.from=adam@adamharvey.name; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=adam@adamharvey.name; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain adamharvey.name designates 209.85.214.170 as permitted sender) X-PHP-List-Original-Sender: adam@adamharvey.name X-Host-Fingerprint: 209.85.214.170 mail-ob0-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:47373] helo=mail-ob0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 66/25-30529-EF97B205 for ; Wed, 15 Aug 2012 06:29:19 -0400 Received: by obbwc18 with SMTP id wc18so2238317obb.29 for ; Wed, 15 Aug 2012 03:29:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adamharvey.name; s=google; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=kGYDECDNazXWl6PIYh97OnbwX0p3DJ9jxBlTerw0aPE=; b=kWLZKTFZHJLxSp4an8s0QrfVM0qe52mIPtp/66hgkL5+rFCXkXqGYJ+0wbByKTsLC0 FBmEFtNF7qq6vzHhJOzb9FXiGLr/WUQBPC1dIghECewC2iGCva4AONFkXclQRE8KqlE5 gVTlpJw5io0xa2Clui94jXfAR3oFmlZsUnuL8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding:x-gm-message-state; bh=kGYDECDNazXWl6PIYh97OnbwX0p3DJ9jxBlTerw0aPE=; b=ZmSowj7gE/qqdirlf53kdyhO2ORSGGVeHDwcpa3UikblB/drzbwula0lZ5ohjjKxmh auVM+wNyRLxbIm8CNjTejru521hq/auOsSIFw9xG/kpMSVjPLlYh76Z0seqZr7pTesOD WC+cBcFXL3oLxwRE8THRVjCb0tVL0XdM76ckjXjHEFK44RK/MjasS8NnklgtYgywaAeS ljV99q6Il1dHtQfvNFuHyGxagMbkIhtzuI2/lZMFP/9es/pIDC4bf3sd7fZFhUHY4QfQ u+7QflJmyTcg7gDPqq+L/NCC25i13g1GzSnoqPhWf6zAf4uOFgj1/9TDxxN+r0v4LIqm 2ZRw== Received: by 10.182.108.71 with SMTP id hi7mr23141859obb.21.1345026556200; Wed, 15 Aug 2012 03:29:16 -0700 (PDT) MIME-Version: 1.0 Sender: adam@adamharvey.name Received: by 10.76.80.70 with HTTP; Wed, 15 Aug 2012 03:28:55 -0700 (PDT) In-Reply-To: References: <502A86AA.2030203@sugarcrm.com> <502B57AE.4070801@sugarcrm.com> <502B5C7F.1070708@sugarcrm.com> <6D84602D0F514FA3B82C11DBAF58AA53@pc> <502B5F8A.5000500@sugarcrm.com> <6281E4639C7248488268ACED88B86B7D@pc> <502B669E.7040702@sugarcrm.com> <1583D6716BFA4BF985E795A1363F465E@pc> <58A080733FC04ABDA51989286868DFC3@pc> Date: Wed, 15 Aug 2012 18:28:55 +0800 X-Google-Sender-Auth: FRvhKAbQyEna_zsScgKVFOZy8Ps Message-ID: To: Nikita Popov Cc: Stan Vass , Stas Malyshev , internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Gm-Message-State: ALoCoQm3+E+Ir/UFst/bAK0ny4tPDyY+oDel85/KiFAEWcj0x1Bm+XzOhqESD3bEkiwsVgaxXDRd Subject: Re: [PHP-DEV] Inline typecasting / typehinting for classes and interfaces From: aharvey@php.net (Adam Harvey) On 15 August 2012 18:15, Nikita Popov wrote: > As already pointed out repeatedly, argument typehints serve the > purpose of defining an interface. No, they are not required to run the > code, that's true. But they still serve an important purpose for > object oriented programming (and, just to make sure that you don't > miss it again: That purpose is defining the interface). Variable > typehints do not, as far as I can see. I was most of the way through writing a much longer e-mail responding to the original post, but you and Stas have summed it up well, really. Type hints actually have a use in the object model of PHP in terms of interface definition. The only uses I can see for these variable hints are: 1. An informative use for IDEs, as previously noted, which is already filled adequately by @var documentation. 2. An assertive use in development: effectively, a different way of writing assert($var instanceof ClassName) to verify your assumptions on variable types. Personally, I don't think either of those justify the addition of the featu= re. The thing is that even ignoring type hints' interface definition functionality and treating them as pure syntactic sugar, type hints have another benefit: if you have several parameters to a function, type hints allow you to verify their classes in one hit, rather than having to make several calls to a verification function or implement something like zpp for objects in userspace. That leads to neater, shorter code. This feature doesn't have that quality: you can only hint one variable at a time, so there's not even a significant saving in time/typing for the developer between (to pick the only version of the syntax I don't find completely objectionable) "ClassName $var =3D $object;" and "$var =3D isType($object, 'ClassName');". In summary, I guess I'm -1 on the feature, and -10=E2=81=B9 on any version = of the feature that looks like a typecast. :) Adam