Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phpactor: Undefined variable "$this" on a fresh Laravel project #20433

Closed
1 task done
Rusydy opened this issue Nov 8, 2024 · 3 comments
Closed
1 task done

phpactor: Undefined variable "$this" on a fresh Laravel project #20433

Rusydy opened this issue Nov 8, 2024 · 3 comments
Labels
bug [core label] language server An umbrella label for all language servers language An umbrella label for all programming languages syntax behaviors php PHP programming language support

Comments

@Rusydy
Copy link

Rusydy commented Nov 8, 2024

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

Screenshot 2024-11-09 at 01 23 54

I just create a new Laravel project using Laravel 11, then I go to console.php. I found that the $this is labelled as undefined.

  • why is that?
  • I would like to solve it, but I am not sure where to start in this case. May I ask for guidance?

Environment

Darwin Users-MacBook-Pro.local 24.0.0 Darwin Kernel Version 24.0.0: Tue Sep 24 23:37:13 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T8112 arm64

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your Zed.log file to this issue.

Zed.log

@Rusydy Rusydy added admin read Pending admin review bug [core label] triage Maintainer needs to classify the issue labels Nov 8, 2024
@Rusydy Rusydy changed the title phpactor: Undefined variable "$this" on fresh Laravel project phpactor: Undefined variable "$this" on a fresh Laravel project Nov 8, 2024
@RemcoSmitsDev
Copy link
Contributor

RemcoSmitsDev commented Nov 8, 2024

Hey @Rusydy, this is not something we could fix inside Zed. This is a shortcoming of the phpactor language server, it does not understand that Laravel bound the closure under the hood. So it's correct that it shows that $this is not defined, because you are not inside a class scope where $this is always bound to that class instance.

Even if you make it clear that the closure is bound to a class, phpactor does not get it.
See the following example:

<?php

final class SomeClass {
    public function returnSomeThing() {
        echo "Some string";
    }
}

$someClass = new SomeClass();

$closure = function() {
    return $this->returnSomeThing(); // `$this` is still not defined accordingto phpactor.
};

$boundClosure = Closure::bind($closure, $someClass);

echo $boundClosure(); // will echo "Some string"

@Rusydy
Copy link
Author

Rusydy commented Nov 10, 2024

@RemcoSmitsDev what can I do to help?
is it need an improvement in Zed or phpactor side?

@RemcoSmitsDev
Copy link
Contributor

No it has nothing to do with Zed, see this issue on the phpactor repo. It's the same issue that you have, it's only with Pest the testing framework.

@SomeoneToIgnore SomeoneToIgnore closed this as not planned Won't fix, can't repro, duplicate, stale Nov 10, 2024
@JosephTLyons JosephTLyons added language An umbrella label for all programming languages syntax behaviors language server An umbrella label for all language servers php PHP programming language support and removed triage Maintainer needs to classify the issue admin read Pending admin review labels Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [core label] language server An umbrella label for all language servers language An umbrella label for all programming languages syntax behaviors php PHP programming language support
Projects
None yet
Development

No branches or pull requests

4 participants