
Phan by Etsy – A Static Analyzer for PHP 7+ - nikolay
https://github.com/etsy/phan
======
debacle
This has been written exclusively with PHP 7 in mind and must have taken a
reasonable amount of thought and a lot of hard work.

The source code looks great, and I could see this supplanting some of the
other tools out there for PHP static analysis.

------
asm
Co-author here. Happy to answer any questions folks have about Phan.

~~~
cweagans
This is awesome. Any plans to add autocomplete functionality similar to HHVM's
typechecker?

~~~
asm
We'd like to get there eventually. Phan populates a sqlite database when
analyzing code (if run with the -s flag). This allows fast runs on single file
changes or patches. We're hoping to use this for things like auto-complete and
finding callers for a class/method/whatever eventually.

For now, we have a primordial Syntastic vim plugin
([https://github.com/etsy/phan/blob/master/plugins/vim/bundle/...](https://github.com/etsy/phan/blob/master/plugins/vim/bundle/syntastic/syntax_checkers/php/phan.vim))
for getting errors into the quickfix view.

~~~
cweagans
That's awesome. If a PR was opened that added autocomplete and/or finding
callers and/or refactoring (and assuming that the code is good), would you
guys be open to merging it? Or would it be delayed so that the core
functionality can be focused on?

~~~
asm
Definitely.

If you want to start working on that, feel free to open up an issue
([https://github.com/etsy/phan/issues/new](https://github.com/etsy/phan/issues/new))
to start a conversation about it.

We currently store method/function callers in the sqlite database (see
[https://github.com/etsy/phan/blob/master/src/Phan/Analyze/Br...](https://github.com/etsy/phan/blob/master/src/Phan/Analyze/BreadthFirstVisitor.php#L922-L929)),
but aren't yet exposing an interface for getting callers. We'll want to store
callers for constants, classes, properties and global variables as well.

------
asm
Clarification on the title of this post; Phan is written in PHP7, but will
analyze code written in any version of PHP.

~~~
debacle
As long as that code can run on PHP7.

------
VeejayRampay
PHP gets so much love and money shoved at it, the Ruby programmer in me finds
it unfair.

That being said, I'm really glad that this helps millions of PHP devs around
the world so bravo to the people working on this.

~~~
dr_zoidberg
PHP gets "so much love and money shoved at it" because, for a lot of problems,
it's the right tool. You can always ask facebook about it.

~~~
vpkaihla
No, the set of problems where PHP is the correct tool is rather small: 1)
existing PHP codebase and 2) small webpages in need of little dynamism.

~~~
jdhawk
You're mistaking a language for a framework/library.

~~~
marssaxman
So does PHP.

------
pka
I _really_ don't want to sound negative, I'm sure a lot of thought and work
went into this, but one has to wonder - would it not be easier to just use
static languages instead of writing static analyzers from scratch for every
dynamic language out there?

~~~
Bulk70
Often the problem being solved by this sort of thing isn't directly about
making it easier to work with a language, but making it easier to hire
developers. The hiring pool for developers who are very good with PHP is much
much larger than a lot of other languages simply by virtue of it being an easy
language to get started with.

This is also why Facebook has spent so much time and effort on things like
HHVM and Hack.

~~~
pka
2 counterpoints:

* Would you hire somebody who wasn't able to learn a new language in a reasonable amount of time?

* Would you let somebody who just started with PHP (by virtue of it being an easy language to start with) work on your backend?

~~~
FranOntanaya
Not counterpoints. The comment above states that the pool of very good PHP
developers is larger. This implies easier hiring (capacity to learn a new
language is not relevant, because it works both ways), which, among other
reasons, would be because they'll be applying first to PHP positions; and
secondly, a very good PHP developer is far from somebody who just started.

~~~
pka
Let me rephrase. I am proposing that (barring very specific requirements which
webdev doesn't justify) there's no such thing as a "good PHP developer". A
good developer is a good developer, period.

A good developer will learn a new language in a reasonable amount of time and
will be able to be productive and write good code in it.

A PHP-only (or X-only for that matter) developer is, by the definition above,
not a good developer.

So why restrict oneself to some random pool of X-only people?

~~~
jschwartzi
What would you call a good developer who knew PHP?

~~~
pka
A good developer :)

------
pbreit
I'm guessing PHP still dominates shared hosting but would anyone ever use it
on AWS, DO, Heroku, own servers, etc?

~~~
jdhawk
Sure, why not? You can still write good applications using PHP. It not just
for legacy servers and pre-installed applications (wordpress/drupal). You
don't even have to use [framework of the month]. Its just a tool. Good
architecture, good practices, and good code are not syntax dependent.

