Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot call method startTag() / endTag() on string #308

Open
lulco opened this issue Jul 24, 2023 · 0 comments
Open

Cannot call method startTag() / endTag() on string #308

lulco opened this issue Jul 24, 2023 · 0 comments

Comments

@lulco
Copy link

lulco commented Jul 24, 2023

Version: all (I use 3.1.1, but it is present in master too)

Bug Description

Found by efabrica-team/phpstan-latte#399

BaseControl::getLabel() has return type Html|string|null, but in compiled template ->getLabel())?->startTag() is used, so it always acts like there is Html or null. No string.

Steps To Reproduce

Create some custom Form Control with method getLabel() returning string and use it in form:

protected function createComponentForm(): Form
{
    $form = new Form();
    $form->addText('title', 'Title');

    $customCheckbox = new class extends Checkbox
    {
        public function getLabel($caption = null)
        {
            return 'this is just string';
        }
    };
    $form->addComponent(new $customCheckbox('Is hidden'), 'is_hidden');
    return $form;
}

In latte:

{form form}
    {input title}
    {label is_hidden}{input is_hidden}{/label}
{/form}

You will get error Call to a member function startTag() on string

Expected Behavior

No error.

Possible Solution

  1. Simple: Remove string as possible return type of method getLabel() (BC break? Probably, but does somebody use it?)
  2. Harder: Change compiled code to check if string is used. But how it will be rendered if it is just string?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant