smarty-php / smarty-php/smarty

Smarty::setExtensions() killing registered filters

Open
#1,006 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
2.3k
Forks
709
PR merge metrics
No merged PRs in 30d

Description

Instructions to add output filters are:

$smarty->registerFilter("output", "protect_email");

Instructions to add custom extensions (overriding the defaults) are:

$smarty->setExtensions([
    new Smarty\Extension\CoreExtension(),
    new MyCustomExtension(),
    new Smarty\Extension\DefaultExtension(),
]);

Unfortunately the latter kills $smarty->BCPluginsAdapter thus disabling any filters. I solved the problem by using:

$extensions = $smarty->getExtensions();
array_splice($extensions, 1, 0, [new MyCustomExtension]);
$this->setExtensions($extensions);

I don't like the style, but at least it is working. But something must be done here, either in the API, or at least the documentation should be updated.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Smarty::setExtensions(), getExtensions(), and BCPluginsAdapter, then reproduce the reported interaction between custom extensions and registered output filters. Done means the filter remains usable after extensions are configured, or the API documentation clearly explains the required behavior and workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.