Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34214 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8551 invoked by uid 1010); 22 Dec 2007 12:58:34 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 8536 invoked from network); 22 Dec 2007 12:58:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Dec 2007 12:58:34 -0000 Authentication-Results: pb1.pair.com header.from=paul.biggar@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=paul.biggar@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.146.183 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.183 wa-out-1112.google.com Received: from [209.85.146.183] ([209.85.146.183:48020] helo=wa-out-1112.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CF/F3-08611-8F90D674 for ; Sat, 22 Dec 2007 07:58:33 -0500 Received: by wa-out-1112.google.com with SMTP id l24so1250598waf.17 for ; Sat, 22 Dec 2007 04:58:29 -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=xpUqrpZ19QJ5Bd2R8rZQlwPg7PLgAXiNBmidBOpSNIk=; b=K1UFF9fGKv9/7mDJrqvyGSIAcDNDHaKYo3obVMqkUmk8CD1oXJvp+fXt9lmbqCg0c0QNP72QFVBOnJqnW+XwH/FAODQiPTmVZQqEcYEeOGHXL+lbbGJMsCB93ui/unQJxKj04mWos4s9gqo0AtsLn1NCYtvssMQm1u+nw+HKeLM= 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=uuKARUEqarcjYLzOYCA74ENAAJJoZIFrN0AtxlPzqjaZMSfVKEyFoBjQf/GbXL9yOrdJLmX+sxolMbIiYzkAXoQ6RiV9kcxZuxH8yHVD/oc8+EOkvSH9qgnD+kzksjlMLPt407x+1x+4EylRE/L3PONRJEH/awn5ySLoBEzbw7g= Received: by 10.114.111.1 with SMTP id j1mr1279037wac.138.1198328309536; Sat, 22 Dec 2007 04:58:29 -0800 (PST) Received: by 10.114.133.14 with HTTP; Sat, 22 Dec 2007 04:58:29 -0800 (PST) Message-ID: Date: Sat, 22 Dec 2007 12:58:29 +0000 To: "Martin Alterisio" Cc: "PHP Developers Mailing List" In-Reply-To: <52dbac0f0712211602y5296932bt72ac90fb577c6af5@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> <52dbac0f0712211602y5296932bt72ac90fb577c6af5@mail.gmail.com> Subject: Re: [PHP-DEV] Refactoring code for namespaces appliance From: paul.biggar@gmail.com ("Paul Biggar") On Dec 22, 2007 12:02 AM, Martin Alterisio wrote: > 2007/12/21, Paul Biggar : > > > > 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. > Because isset is actually a keyword. Right, the phc grammar doesnt differentiate between built-ins and functions, even though the PHP grammar has rules for each. You just need a list of the built-ins, such as isset, etc. You'll see when you start working with phc, but the point I was making was that this isnt hard. > > > 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. > > Maybe some workaround can be found to str_replace the namespace separator, > but I think this wouldn't be optimal and possibly harm code readability and > maintainability. Consider a factory method: > > class Factory { > public static function create($what, $arguments) { > switch ($what) { > case 'bananas': > $class = 'Food_Fruit_Banana'; > break; > ... > } > return $class::create($arguments); > } > } > ?> > > An automated refactoring would be tempted to do: > > class Factory { > public static function create($what, $arguments) { > switch ($what) { > case 'bananas': > $class = 'Food_Fruit_Banana'; > break; > ... > } > $temp = str_replace('_', '::', $class); > return $temp::create($arguments); > } > } > ?> > > Which I think is not the proper way to refactorize this code. > This would be, IMHO, the right way to refactorize this code: > > class Factory { > public static function create($what, $arguments) { > switch ($what) { > case 'bananas': > $class = 'Food::Fruit::Banana'; > break; > ... > } > return $class::create($arguments); > } > } > ?> > > Considering the variants and possible uses of this syntax, I'll say it's > better to leave this job to the coder rather than to an automated job. True, as I'm sorry to say that we dont have the facilities to automatically match the definition of variables to where they are used. However, once you have a list of class_names, a global replace on all strings may be all you need. Paul -- Paul Biggar paul.biggar@gmail.com