smarty icon indicating copy to clipboard operation
smarty copied to clipboard

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

Open Chrissyx opened this issue 1 year ago • 3 comments

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?

Chrissyx avatar Mar 30 '24 22:03 Chrissyx

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 avatar Apr 03 '24 07:04 wisskid

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

wisskid avatar Apr 03 '24 07:04 wisskid

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.

Chrissyx avatar Apr 03 '24 08:04 Chrissyx