Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34210 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61294 invoked by uid 1010); 21 Dec 2007 22:09:28 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 61279 invoked from network); 21 Dec 2007 22:09:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Dec 2007 22:09:28 -0000 Authentication-Results: pb1.pair.com smtp.mail=paul.biggar@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=paul.biggar@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.146.178 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: paul.biggar@gmail.com X-Host-Fingerprint: 209.85.146.178 wa-out-1112.google.com Received: from [209.85.146.178] ([209.85.146.178:10004] helo=wa-out-1112.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 80/80-54742-7993C674 for ; Fri, 21 Dec 2007 17:09:27 -0500 Received: by wa-out-1112.google.com with SMTP id l24so787714waf.17 for ; Fri, 21 Dec 2007 14:09:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=zo/mAuGeIDf8FT/YLKC+oYJ83Vs5e63GMa30T2L6sMc=; b=V8g/ieCa8T50qnX8HAbwVvIfUAwYnO4O2wLTpo737yFm9y3N+P6+vK0SZyzvyXeM6hcPscqb0wa+5SBTZfIxY8iruK8PY/L1fAY4bzHEn4WaaNmo7lkH7hT4tCFBdHyc2INn1UCWycDoufVX6JRi892Zjy43+kfOiU29Ri01jY8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=F70GWNZc2IylwFZwITLsrL06YVhcpaY5ZlPthD3ejS0pz3rCINShpNKXsGZ2TyGJReIGlgJOR/6C3UQnei35f5R7JiQTY3vydkLKYOwXYJeeWr3L9/SWYSIA1pWTB3VPqWPedBGUct9b+ReP33wwuv8JklJtVYAmq/R3Okewnx4= Received: by 10.115.95.1 with SMTP id x1mr1957479wal.94.1198274963949; Fri, 21 Dec 2007 14:09:23 -0800 (PST) Received: by 10.114.133.14 with HTTP; Fri, 21 Dec 2007 14:09:23 -0800 (PST) Message-ID: Date: Fri, 21 Dec 2007 22:09:23 +0000 To: "Martin Alterisio" Cc: "PHP Developers Mailing List" In-Reply-To: <52dbac0f0712211230v17c0762cs4b9e37db29e2bc34@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <52dbac0f0712211230v17c0762cs4b9e37db29e2bc34@mail.gmail.com> Subject: Re: [PHP-DEV] Refactoring code for namespaces appliance From: paul.biggar@gmail.com ("Paul Biggar") Hi Martin, On Dec 21, 2007 8:30 PM, Martin Alterisio wrote: > I've been pondering about how to algorithmically/mechanically prepare a non > namespaced code for namespaces appliance. This would be a first step which > will just prepare the code for namespaces in a safe way, but not to profit > from aliases created by use. The latest will have to be implemented manually > (IMHO). phc (www.phpcompiler.org) would be suitable for this purpose. It has good support for nearly all of the features you need. > I've come up with the following, for an organization model of a class per > file. > Please review. > > 1) find the class definition and reduce the class name to namespace/class > 2) add namespace declaration on top of file > 3) replace class name in definition with short name So far this would be trivial. > 4) find all function calls (not method calls) which are not keywords (array, > isset, unset, list, etc) and prefix them with :: list, array etc wouldnt be confused with functions. Functions are just methods without target. You'd need a short list of functions such as empty, unset etc to avoid. > 5) find all class names (static method calls (no self:: nor parent::), new, > catch, type hints, instanceof, extends, implements) and: All of these are trivial. > 5a) replace separator used (possibly: _) with namespace separator (::) > 5b) IF the class has no namespace (ie global namespace) prefix the class > name with :: > 5c) IF the namespace of the class starts with the same namespace found in > (1), remove it or prefix it with namespace:: > (although this is not necessary) This would be easy too. > 6) find static method calls with variables used as class name, and mark them > for user handled refactoring I'm not sure why this couldnt be done automatically, but finding static method calls is also easy. You could add comments to mark these fairly easily. > 7) find internal functions that use callables (call_user_func, array_map, > array_filter, etc) and mark them for user handled refactoring A lot of this could be automated, but there would of course be some which would require marking. > Later on, a methodical way of adding use statements for reducing the class > names used, can be implemented. Although this might be more complicate than > it seems if the method has to be careful to avoid creating possible name > clashes. > > If anyone has a comment on this, I'll be more than grateful if you share. If you need any advice, on this, please let me know. Paul -- Paul Biggar paul.biggar@gmail.com