smarty-php / smarty

Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.
Other
2.23k stars 703 forks source link

Error: Call to undefined method Smarty\Smarty::setErrorUnassigned() #979

Open Chrissyx opened 4 months ago

Chrissyx commented 4 months ago

While upgrading to Smarty 5 I encountered this fatal error by calling this: $this->smarty->setErrorUnassigned(true);

Not a big deal, the property is still there and I can set it directly like this: $this->smarty->error_unassigned = true;

However the upgrade docs do not mention this. So I'm wondering are the getter/setter removed intentionally and the docs are missing some API method changes? Or should setErrorUnassigned() still work?

wisskid commented 4 months ago

Wow, after inspecting the code, I was going to say that setErrorUnassigned does not exist in Smarty 4 either. But even though it is not defined, calling $this->smarty->setErrorUnassigned(true); indeed actually works. It seems to be routed through \Smarty_Internal_Extension_Handler::_callExternalMethod() which magically allows you to get/set Smarty properties.

I cannot find any reference of setErrorUnassigned in the documentation or anywhere else on the internet, so it seems you guessed this one by accident? I'm wondering what to do about this. Adding a getter/setter seems the easiest fix. And documenting it. But there might be more magic getters/setters to consider.

wisskid commented 4 months ago

Also, there is overlap with $smarty->muteUndefinedOrNullWarnings()

Chrissyx commented 4 months ago

I'm using this setter since Smarty 3.0 RC4. It always worked. If this is no longer intended, I can migrate to set the property directly. It would be just nice to have a hint in the docs about the removed magic setters/getters in general.