On Dec 22, 2007 12:02 AM, Martin Alterisio <[EMAIL PROTECTED]> wrote:
> 2007/12/21, Paul Biggar <[EMAIL PROTECTED]>:
>
> > > 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:
>
> <?php
>  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:
>
> <?php
>  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:
>
> <?php
>  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
[EMAIL PROTECTED]

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to