Using view layouts echoes void return type. |
Hi,
while playing around with PHPStan I noticed that the current CI4 analysis level will complain about some basic handling of view layouts. In the Docs it is stated that views can extend view layouts by writing: PHP Code: <?= $this->extend('default') ?> While this in principle is working fine and without any warning, PHPStan complains that we try to output the return value of a method that has a void return type. Now I know we specifically exclude the 'views' folder in static analysis, however, I feel that PHPStan is correct here. The correct implementation would be: PHP Code: <?php $this->extend('default') ?> I personally feel, that sparing the two characters is not really worth the inconsistency here. How do others feel about that?
It is 6 not 2 extra characters, the = sign replaces echo.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
That's correct in principle, but we are not echoing anything here :-)
The second example works just fine without any echo.
This looks like an error in the user guide. You are right, extend() return void, there's nothing to echo.
PHP Code: /** Source: https://github.com/codeigniter4/CodeIgni...w.php#L398 ...and it's the same with section() and endSection(). This: PHP Code: <?= $this->extend('default') ?> ...should be this: PHP Code: <?php $this->extend('default') ?>
This should be changed, regardless of how many characters are involved. A detected error should not be neglected IMO.
We should be really trying to uncover the suppressed errors of phpstan. ? |
Welcome Guest, Not a member yet? Register Sign In |