Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66618 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35204 invoked from network); 14 Mar 2013 16:26:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Mar 2013 16:26:35 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.220.172 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.220.172 mail-vc0-f172.google.com Received: from [209.85.220.172] ([209.85.220.172:65177] helo=mail-vc0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8A/84-07586-A3AF1415 for ; Thu, 14 Mar 2013 11:26:35 -0500 Received: by mail-vc0-f172.google.com with SMTP id hr11so521273vcb.17 for ; Thu, 14 Mar 2013 09:26:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type:x-gm-message-state; bh=R35JZZg3hZUiNZE2zSUi/PySNbT/MFDkdYVRrSEQPeg=; b=eALfMYIsqVo2jxBSE+f89ixlSCqK2lTccwJqNo/W0URFUGnp6sdJ/XlfdUGuTXrJ0y wfGKezzyhHEzrBuZsdnyGU+Gl3snjFNhhFm1JotppC8U1zPWBMfifHAoO/bqOIDQRZat wkJY3ZL6vRyU/+YbuunQJ8t4NopUAGppcKtSwITFVquCJpZ/QpiACUdiPVjLpW1B2bAa 72gccHBxcfr0UlLroIukfJeCnNg8CgZngf9OG5fHZ8Vvlfv9452SjJg9Gjg0DZVtc6kq kqrdWGPXXN1TU3agTHqCIZM0n/mpRP4OfTUjCESfQBeYSj/IuMHj7LMP0pSrhx+R8Jxe pyEQ== MIME-Version: 1.0 X-Received: by 10.220.156.8 with SMTP id u8mr2472606vcw.24.1363278391719; Thu, 14 Mar 2013 09:26:31 -0700 (PDT) Received: by 10.58.208.234 with HTTP; Thu, 14 Mar 2013 09:26:31 -0700 (PDT) Date: Thu, 14 Mar 2013 12:26:31 -0400 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary=f46d043c817a44d27604d7e4fce4 X-Gm-Message-State: ALoCoQk4HHZ+DA2BGFLkbXjygo1v/hnvirlaLUyZ2AstX5NursLhChT5um45DGf9UUMapoDBUBG7 Subject: static type-references From: rasmus@mindplay.dk (Rasmus Schultz) --f46d043c817a44d27604d7e4fce4 Content-Type: text/plain; charset=ISO-8859-1 Hey List, What do you think about adding a typeof() operator to PHP? It could go something like this: class User { public $name; } /** * @var ReflectionClass $user_type * @var ReflectionProperty $user_name_property */ $user_type = typeof(User); $user_name_property = typeof(User::$name); Mind you, this is an operator and not a function - User and User::$name are interpreted as symbols. This would allow for static analysis of class and property-references. Why? Because you can't use static analysis on code like this: $user_type = new ReflectionClass('User'); $user_name_property = new ReflectionProperty('User', 'name'); 'User' and 'name' are just strings, and strings are dead matter when it comes to static analysis. Most form builders and ORMs (and other reflective meta-programming components) require references to properties or classes, e.g.: $form->textInputFor($user, 'name'); There is no knowledge that 'name' actually refers to the symbol User::$name and hence to way to perform static analysis or use refactoring tools on this code. Compare to: $form->textInputFor($user, typeof(User::$name)); This code can be analyzed and refactored, because the reference to the User::$name property is now literal. Actually having to type out typeof() may not be the most elegant approach, and using this syntax it does resemble a function - having a more distinct syntax might be better. But those things aside, what do you think about having a way to statically reference types and members? Thanks, Rasmus Schultz --f46d043c817a44d27604d7e4fce4--