Kate
1
I have a bit of code that produces an error since Kirby 3.9. and with PHP 8.2 (it works fine with PHP 8.1). I checked it with the debugger:
<div class="tag">
<?php foreach($page->tags()->split(',') as $tag): ?>
<a <?php e($tag == urlencode(param('tag')), '') ?> href="<?= url('results/tag:' . urlencode($tag))?>"><?= $tag ?></a>
<?php endforeach ?>
</div>
The code is supposed to create a new “result”-page which lists all arcticles with a certain tag.
Has anybody an idea?
What sort of error? And referring to what line in your code?
Kate
3
Oh, what a quick reply…
Specifically it is this line:
<a <?php e($tag == urlencode(param('tag')), '') ?> href="<?= url('results/tag:' . urlencode($tag))?>"><?= $tag ?></a>
And in the Debugger it says:
Whoops \ Exception \ ErrorException (E_DEPRECATED)
urlencode(): Passing null to parameter #1 ($string) of type string is deprecated
should then be
urlencode(param('tag') ?? '')
On a side note, what’s the purpose of this piece of code, doesn’t really do anything and can be remove, or you should add a class active
here.
Kate
5
Removing the whole bit did the job. I must confess that I have no idea why I used this part of code. It’s quite a long time I made it.
But thanks a lot for taking your time on a chilly Sunday.
What you probably wanted:
<?php e($tag === urldecode(param('tag') ?? ''), 'class="active"') ?>
1 Like