-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Null-coalescing does not work when method returns null #4499
Comments
Can you share a small reproducer? Or at least, tell me if |
I think I know: the method and argument does exist, and the method returns an empty string or |
It can be reproduced when object getter is used. Here is example: require_once 'vendor/autoload.php';
class SomeClass {
private ?string $var = null;
public function getVar(): ?string {
return $this->var;
}
}
$loader = new \Twig\Loader\FilesystemLoader('templates');
$twig = new \Twig\Environment($loader);
$a = new SomeClass();
echo $twig->render('test.twig', [
'a' => $a,
]); {{ a.var ?? 123 }} Twig 3.17 Output:
Twig 3.16 Output:
|
New release published. |
should return
nope
but the result is emptytried to add a test to
tests/IntegrationTest.php
but not sure how to inject an object fortests/Fixtures/tests/null_coalesce.test
this broke my code after latest release: i had a function where it accepts only string type but then the null coalesce stopped working and null was passed instead of the fallback string
The text was updated successfully, but these errors were encountered: