pdt
pdt copied to clipboard
Short arrow closure syntax gives warnings with function args
Hello ! Since 2020-03 and then still present in 2020-06 when I write a closure using short arrow syntax (PHP >= 7.4), closure arguments raise a Variable {$foo} is undefined warning.
Version is:
Eclipse IDE for PHP Developers (includes Incubating components)
Version: 2020-06 (4.16.0)
Build id: 20200615-1200
I have quite a few addons installed, but I noticed the bug prior to installing it.
- OS: Running ArchLinux, uname output:
Linux guinevere 5.7.6-arch1-1 #1 SMP PREEMPT Thu, 25 Jun 2020 00:14:47 +0000 x86_64 GNU/Linux
Steps to reproduce the behavior:
- Open a PHP file,
- Write a short arrow syntax closure with at least one argument.
A few screenshots following.


OK that's not really visible, but notice the yellow underline on the closure parameter name, then at its usage.
Hi,
I'm having this warning too Eclipse PDT 8.0.0.202007171531 (@fedora 34)
Hi, Bug always present in PHP Development Tools (PDT) 8.0.0.202112011911
@zulus I updated this morning, I'm now running version 8.1.0.202306071122 and I'm still experiencing this bug.
@pounard Can you post example code?
First one found in my currently opened project (sorry it's french domain code):
/**
* Récupère le ou les destinataires des contacts entreprise de la demande.
*
* @return Destinataire[]
*/
public function getEntrepriseDestinataireAll(): array
{
return \array_filter(
\array_map(
fn (Contact $contact) => $contact->email ? new Destinataire((string) $contact->id, $contact->email) : null,
$this->getEntrepriseContactAll()
)
);
}
Here the $contact variable inside the closure body is yellow underlined with the following message on hover:
Variable '$contact' is undefined
By the way, it also yellow underlines the null keyword, also the (string) cast, without any other message that the given one (I think it's underlining the whole line actually, but yellow on white is barely visible, I have to change that color setting).
Here is a screenshot:
Sorry, I can't really screenshot the tooltip...
Forgot to mention: PHP validation for this project is configured to PHP 8.0, fun fact, when switching to PHP 8.2, I don't have warnings in most case, except this one, see:
Now, only the part in new Destinataire((string) $contact->id, $contact->email is underlined as being an warning, the rest is fine.
So there are two bugs here:
- first, it works with PHP 8.2 parser, but not previous ones (although I didn't tested using PHP 8.1, this project is kind huge to validate),
- now that it works in 90% percent of use cases, there are still some pitfalls in 8.2 parser.
Validation message is still the same:
Variable '$contact' is undefined
Arghh! I completely forgot about tenary operator changes in PHP 8, is no longer left associative. So it’s not problem in validator (works correctly), but in php 8 parser, it produce wrong AST. Separate task will be needed. Can you prepare? If not I’ll do it at night
Can you prepare?
I'm sure to understand the question here ?