| Summary: | [PHP 5.3] Adding use statement on wrong place | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | z_Archived | Reporter: | Sylvia Tancheva <silviya> | ||||||
| Component: | PDT | Assignee: | PHP Core <php.core-inbox> | ||||||
| Status: | CLOSED FIXED | QA Contact: | Ilina Stefanova <ilina.s> | ||||||
| Severity: | normal | ||||||||
| Priority: | P1 | CC: | ganoro | ||||||
| Version: | unspecified | ||||||||
| Target Milestone: | --- | ||||||||
| Hardware: | PC | ||||||||
| OS: | Windows XP | ||||||||
| Whiteboard: | |||||||||
| Attachments: |
|
||||||||
first I remove the ; after
class MyException extends \Exception {
}
it works as expected
so I think the issue is about parser,so I checked file php_ast_parser.cup,I found(from line 371)
if (!(statement instanceof EmptyStatement) && lastStatement instanceof NamespaceDeclaration && !((NamespaceDeclaration)lastStatement).isBracketed()) {
((NamespaceDeclaration)lastStatement).addStatement(statement);
} else {
sList.add(statement);
}
if I change the above code to :
if (lastStatement instanceof NamespaceDeclaration && !((NamespaceDeclaration)lastStatement).isBracketed()) {
((NamespaceDeclaration)lastStatement).addStatement(statement);
} else {
sList.add(statement);
}
the issue has gone!
so probably it is intentional.
Created attachment 181607 [details]
patch
Hi zhao,
You can look at this patch.
Created attachment 182452 [details]
patch
fix the bug in php_ast_parser.cup
Hi Xu, I have reviewed your patch,and it is really very nice.sometimes the parser could not parse the php file correctly,and if use your patch we do not need to worry about this when we call method UseStatementInjector.getCurrentNamespace. Yes, I think this patch can help #267813 too. change status Verified on Windows XP, 32 bit with Zend Studio 9.0.0, build 179. |
Use code: <?php /** * */ namespace NS\Registry; class MyException extends \Exception { } ; class Registry { protected static $_registry = array (); static public function register($key, $value, $isPersistent = false) { if (isset ( self::$_registry ['$key'] )) throw new My| <-- Code Assist here, choose MyException } } As a result: - use directive is inserted right after the php opening tag (and the comments if any), but before the namespace declaration, which results in compilation error. - btw, the use directive isn’t needed in this case at all <?php /** * */ use NS\Registry\MyException; namespace NS\Registry;