-
Notifications
You must be signed in to change notification settings - Fork 4
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
{capture $link}Foo:bar{/capture}
throws "link() expects string" on level 7
#398
Comments
So problem is only false? Not Latte\Runtime\Html? Well we can transform the compiled code. |
With strict types enabled for Engine your code will even not work. https://github.com/nette/latte/blob/master/tests/common/Engine.strictTypes.phpt Maybe you should cast capture output to string? Or not using capture at all here. |
This is one of the bugs where I don't know where the problem is and who should fix it. You're correct that with strict types it won't work and that casting to string would fix it. |
…d one in the link A workaround efabrica-team/phpstan-latte#398 but I have to say I like this better.
The issue here is very similar to efabrica-team/phpstan-latte#398 and the workaround is a bit different although type-casting would also work for the case reported in that bug. Fixes errors like "Parameter #2 ...$args of method MichalSpacekCz\Templating\Filters::format() expects int|string, Latte\Runtime\Html|string|false given."
I think this is not the bug of phpstan-latte extension. I would rather say it is possible bug found by it :) |
A possible bug where though? 😅 |
In your code O:-) and also it is weird that capture returns Html and not string :) I think it is not some public knowledge |
It's not even documented I can't use a captured variable for links or that I have to type-cast it to string. |
Maybe we should check the original compiled template :)) but I don’t think it is added by our extension. Also maybe it is not documented because it works - Html is automatically casted thanks to non-strict template classes. Then it is wrong phpstan behavior? Should it use Stringable classes / classes containing __toString() as strings? |
I've checked the original Latte-compiled template and the code is basically the same. It could also be Latte, it could cast whatever comes to link() for example to strings. Or document that what I was doing is not supported. Or throw an exception. This is one of the things I'm not sure what's wrong and where. I could just write that part in a different way (and I've already done that) and be done with it but that doesn't help the thing (we just don't know which one) get better. |
You're capturing HTML and pasting it into the place where plain text is expected, so it doesn't work. It could be done like this: {if}
<script type="text/plain">
{capture $link}Foo:bar{/capture}
</script>
{/if false} Then |
It actually works (the template compiles just fine and works as expected), and I understand why, but PHPStan Latte says it doesn't, which I also understand why. But the difference is why I've filed the bug in the first place :-) I've already found a nice solution: I've stopped using |
This is something I'm not sure is a bug, or something that can be fixed or changed in phpstan-latte but you tell me.
My template contains this:
which can probably be minimized to just:
and I get this:
The compiled code looks like this
now the error seems more or less correct because of these lines
So in theory
$ʟ_tmp
can indeed benew \Latte\Runtime\Html(\ob_get_clean())
or a result of\ob_get_clean();
which is a string or false.But, is there something I can do with that? I can change it to something like
and the error will disappear but the original code seems to be a legal (and working) Latte expression.
The text was updated successfully, but these errors were encountered: