Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision Last revision Both sides next revision | ||
phantm:faq [2010/05/04 14:15] philippe.suter created |
phantm:faq [2010/05/04 15:35] ekneuss |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== FAQ ====== | + | ===== FAQ ===== |
- | Plop? | + | Here is a list of common questions along with their answer. |
- | Plop | + | |
+ | ==== What des "phantm" mean? ==== | ||
+ | |||
+ | //phantm// is an acronym of "PHp ANalzer for Type Mistakes" | ||
+ | |||
+ | |||
+ | |||
+ | ==== Why phantm? ==== | ||
+ | |||
+ | We believe that even if PHP puts close to no restrictions on types, it is | ||
+ | still interesting to verify that they are handled correctly. It is easy to | ||
+ | identify patterns of type errors that are directly caused by programming mistakes. | ||
+ | We thus bring some of the advantages of statically typed languages to PHP. | ||
+ | |||
+ | |||
+ | ==== I get lots of errors, does that mean my code is all wrong? ==== | ||
+ | |||
+ | No. First of all, static analysis has its limitations. There will always be | ||
+ | false positives given the semantics of PHP. However, you can help //phantm// do | ||
+ | a better job, by precisely annotating your code. See [[phantm:annotations|Annotations]] for more | ||
+ | details. | ||
+ | |||
+ | Also, you'll notice that by default //phantm// is quite picky about uninitialized | ||
+ | values, or implicit type conversions. | ||
+ | |||
+ | For instance, on the code %%$a = "2"; echo $a / 2;%%, //phantm// will report that | ||
+ | %%$a%% is not a valid operand for /. Even though those "errors" are not | ||
+ | critical and PHP itself handles them gracefully in most cases, it is still | ||
+ | considered "bad style" by //phantm//. | ||
+ | |||
+ | |||
+ | ==== I get errors mentioning Top or Bottom, what are those types? ==== | ||
+ | |||
+ | //phantm// represents types as so-called Lattice elements. In the type Lattice, | ||
+ | ''Top'' represents the supertype of all types, and ''Bottom'' represents the | ||
+ | subtype of all PHP types. In short, ''Top'' means "Every possible types" | ||
+ | (including uninitialized values) and ''Bottom'' means "No type". | ||
+ | |||
+ | |||
+ | |||
+ | ==== What is the difference between Top and Any ? ==== | ||
+ | |||
+ | ''Any'' represents types of defined values. However, the fact that a variable | ||
+ | is undefined is represented as a type as well, namely ''Uninitialized''. ''Any'' | ||
+ | does not include ''Uninitialized'', but ''Top'' does. | ||
+ | |||
+ | |||
+ | |||
+ | ==== I have code that uses references, but it's not analyzed properly by phantm, why? ==== | ||
+ | |||
+ | References are currently ignored by //phantm//. | ||
+ | |||
+ | |||
+ | ==== I get errors on my arrays, but the error itself is riddled with "..."s ? ==== | ||
+ | |||
+ | //phantm// will try to reduce the size of errors as much as possible by | ||
+ | limitting the string representation of types to the parts that are | ||
+ | relevant for the type error. | ||
+ | |||
+ | |||
+ | ==== What is the Numeric type ? ==== | ||
+ | |||
+ | ''Numeric'' is simply ''Float or Int''. Unlike PHP's ''is_numeric'', It does not | ||
+ | include numeric string literals. | ||
+ | |||
+ | |||
+ | |||
+ | ==== I'm getting weird complicated types in my errors, with my unannotated code, why doesn't it say Any? ==== | ||
+ | |||
+ | This is because //phantm// refine types used in expressions. For instance, given the code | ||
+ | |||
+ | <file> | ||
+ | function foo($b) { | ||
+ | $a = $b / 2; // (1) | ||
+ | $c = $b / 3; // (2) | ||
+ | } | ||
+ | </file> | ||
+ | |||
+ | Before (1), ''$b'' is ''Any'' and thus issue an error since / expects two numeric | ||
+ | types. However, after (1), we can assume that ''$b'' is ''Numeric''. This is | ||
+ | essential, as it dramatically reduces the number of errors! For instance, on | ||
+ | (2), no error is issued. | ||
+ | |||
+ | However, if ''$b'' is later used where a ''String'' is specifically required, you'll | ||
+ | get an error looking like: ''expected String, found Numeric''. | ||
+ | |||
+ | |||
+ | ==== Can I ask phantm to focus on most interesting errors? ==== | ||
+ | |||
+ | Yes! Usually, the option %%--quiet%% or even %%--shy%% will do a decent | ||
+ | job on removing the least significant errors. Note however that it might potentially hide | ||
+ | important notices. | ||