Can I call methods on an object represented by a string variable? I tried the attribute twig function for this but that did not work.

Essentially, what I'd like to achieve is the following:

{# This string variable is a name of the object #}
{% set myForm = 'form' %}
{# I'd like to call the 'errors' method on the 'form' object #}
{% set formErrors = myForm.errors %}


The problem with the above code is that the errors method will be called on the myForm object instead of the form object.

Is there any way to achieve what I'm trying to do here?
Twig's attribute function allows you to set the method as a string and not the object. The object has to be an actual object, even with that function.

{% set object = craft.entries.order('postdate').last() %}
{% set method = 'title' %}

{{ attribute(object, method) }}


The only workaround I can think of is to link your object-representing string to an actual object in your template. But this makes little sense as you probably wouldn't have set it as a string to begin with, hehe. Anyways:

{% if string == "craft.entries.order('postdate').last()" %}
    {% set object = craft.entries.order('postdate').last() %}
{% endif %}

{{ attribute(object, method) }}