question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`use TraitName` breaks find_use command.

See original GitHub issue

When there are traits in use within a class, the find_use command is broken.

This is due to the use keyword having more than one meaning, dependent on context. One meaning is to “import” or “alias” a namespaced class. Another meaning is to “insert” a trait, and another meaning is to import a variable from an outer scope.

It seems that SublimePHPCompanion’s find_use command is only taking the first meaning into account. It feels like the command simply looks for the nearest use keyword and adds the imports there. If a use keyword exists inside a class definition, everything breaks causing syntax errors.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
stale[bot]commented, Jan 12, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

0reactions
g105bcommented, Jan 25, 2017

This is what I expect:

<?php
namespace Test;

use \some\namespace\Thing; // ** This is where the namespace import should be put. **

class Example {

    use SomeTrait;
    use AnotherTrait;

    public function __construct() {
        $thing = new Thing(); // find use here breaks things because of the traits.
    }
}

This is what I actually get:

<?php
namespace Test;

class Example {

    use \some\namespace\Thing; // ** it is actually added here - as if it were a trait - which breaks things **
    use SomeTrait;
    use AnotherTrait;

    public function __construct() {
        $thing = new Thing(); // find use here breaks things because of the traits.
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found