Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62172 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2615 invoked from network); 15 Aug 2012 08:39:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Aug 2012 08:39:13 -0000 Authentication-Results: pb1.pair.com header.from=sv_forums@fmethod.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=sv_forums@fmethod.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fmethod.com from 209.85.215.170 cause and error) X-PHP-List-Original-Sender: sv_forums@fmethod.com X-Host-Fingerprint: 209.85.215.170 mail-ey0-f170.google.com Received: from [209.85.215.170] ([209.85.215.170:39238] helo=mail-ey0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 09/51-30529-0306B205 for ; Wed, 15 Aug 2012 04:39:13 -0400 Received: by eaao11 with SMTP id o11so374576eaa.29 for ; Wed, 15 Aug 2012 01:39:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:from:to:cc:references:subject:date:mime-version :content-type:content-transfer-encoding:x-priority:x-msmail-priority :x-mailer:x-mimeole:x-gm-message-state; bh=DEE1ekD1ph8MXrQo2ZYtRZQrXcChszB8iiher81Wjec=; b=DarK4Kqmcmp1jCXO0LH4Stog08PQRgfafb91slKd1bJvnpAyTjs7/J2i1RyVArwl7H bAIDcDleqDz9qtSh3RP73FXhehHvAYjHmNQzkurTEfJ89CZ6mVuTBamQDj2BpV0RiPIC dip6hLm40hjGnefqZTYwG5Q6Zzt5XJrwYTi+KEZLPeckkEM0fRSGm+4eF/bbDmoMkdb4 50WzuMwkeatKRIUHwzlIbLbGCfXIy2w5G4O2d2rsoz0pTKMuTCAnwrNE3+uxnyDKw3EL Hg1vyRUBjQT/Oem6r49aap6KUj4hWAUopC3i1kdx2KRoVQn5eJCTTt5GaarJjOal/P5a QeSg== Received: by 10.14.179.200 with SMTP id h48mr23575752eem.12.1345019950314; Wed, 15 Aug 2012 01:39:10 -0700 (PDT) Received: from pc (95-42-66-13.btc-net.bg. [95.42.66.13]) by mx.google.com with ESMTPS id h2sm2218716eeo.3.2012.08.15.01.39.08 (version=SSLv3 cipher=OTHER); Wed, 15 Aug 2012 01:39:09 -0700 (PDT) Message-ID: To: "Nikita Popov" Cc: "Stas Malyshev" , "Anthony Ferrara" , "Levi Morrison" , References: <502A86AA.2030203@sugarcrm.com> Date: Wed, 15 Aug 2012 11:39:06 +0300 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="ISO-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-Gm-Message-State: ALoCoQnrbXRg74SlIK50w6A9EvwnPTCwtxHh3gJIK37z5fwNhC9R6mpZ+Fq9ZPpKxfgFAy4vg5JQ Subject: Re: [PHP-DEV] Inline typecasting / typehinting for classes and interfaces From: sv_forums@fmethod.com ("Stan Vass") > On Wed, Aug 15, 2012 at 10:06 AM, Stan Vass wrote: >> I'd like to also ask people to read what the intended effect of the >> proposal >> is instead of going into abstract discussions about how casting one class >> to >> another doesn't make sense (this is not what's being proposed). > > I think you confused everyone by a) having "typecasting" in the title > and b) starting with the (Foo) casting syntax (so everyone assumed > that you indeed want some kind of class casts, whatever that may be). I had "typecasting / typehinting" in the title, and I'd like to remind everyone again that in dynamically typed languages class casts are often implemented as a basic validation operation, consistent with what I proposed. > Regarding the actual proposal, could you maybe clarify the use-cases > for this? I can see that it could be useful in principle, but your > actually named use cases confuse me somewhat. In particular, I don't > see how this would help dependency injection containers. I can see > that it helps service locators and registries, but both of those are > considered antipatterns, so there is no reason to add additional > language features for them. DICs are only used to inject top-level > dependencies, so in that case types should be fairly well covered by > parameter type hints. Two use cases apart from registries: PHP has no typed iteration and arrays, so you the only way to guarantee (and the IDE to know) the type of a variable in these cases is a hint: Foo $bar = $array[1]; foreach ($array as Foo $item) { ... } Automatically this applies to everything that uses ArrayAccess as a shorthand too, and properties of anonymous objects (stdClass). The current alternative is peppering code with pseudo-PHPDoc inline hints, and instanceof assertions which truly is a facility the language core should provide, instead of us emulating it. Stan