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 use object of type Closure as array #17

Open
emergingdzns opened this issue Mar 20, 2020 · 3 comments
Open

Cannot use object of type Closure as array #17

emergingdzns opened this issue Mar 20, 2020 · 3 comments

Comments

@emergingdzns
Copy link

Bug Report

When attempting to instantiate Laminas Filter I'm getting an error about the Closure as array.

Q A
Laminas Filter Version(s) 2.9.3

Current behavior

Getting the following error:

In AddonLoader.php line 29:                     
Cannot use object of type Closure as array  

How to reproduce

Added laminas filter to my laravel project using composer.

Added use Laminas\Filter\StripTags; to my controller.

I then applied the following code to my method:

$allowedElements = [
       'allowTags' => [
               'ul','li','ol','br','p','b','strong','i','em','h1','h2','h3','h4','h5','a'
       ],
        'allowAttribs' => [
               'href'
      ]
];
$filter = new StripTags($allowedElements);
$htmltext = $filter->filter($htmltext);

Expected behavior

Should result in a string for $htmltext.

@weierophinney
Copy link
Member

I don't think this error is due to our StripTags filter.

To verify, I wrote the following test method, which I placed in our test/StripTagsFilterTest.php:

    public function testConstructorWorksWithoutErrors()
    {
        $html = <<< 'END'
            <p>
                <span>This is some <a href="https://getlaminas.org">text with a link</a></span>
            </p>
END;
        $expected = <<< 'END'
            <p>
                This is some <a href="https://getlaminas.org">text with a link</a>
            </p>
END;
        $allowedElements = [
            'allowTags' => [
                    'ul','li','ol','br','p','b','strong','i','em','h1','h2','h3','h4','h5','a'
            ],
                'allowAttribs' => [
                    'href'
            ]
        ];
        $filter = new StripTagsFilter($allowedElements);
        $this->assertSame($expected, $filter->filter($html));
    }

This test passes as-is currently.

Looking in your write-up, the error message indicates the problem is in AddonLoader.php line 29; is it possible that that file is the problem? There are no closures being used here, which makes me think the issue is elsewhere.

@emergingdzns
Copy link
Author

Apologies for the delay in response. COVID threw everything out the window.

Anyway, I'm still having an issue. Once I installed Laminas via composer require, I get that error about AddonLoader. So, to fix it I had rename the vendor folder, and copy the previous backup of the vendor folder in (without Laminas in it). Error goes away.

So then I copied in just the Laminas folder from the renamed vendor folder. I did composer dump-autoload too hoping to make sure that it would rebuild the autoloader and possibly include Laminas.

I attempted to run my script. I now get an error that StripTags does not exist.

I attempted to install it locally in the same repo (instead of on the server) and I get a problem installing it:

Using version ^2.9 for laminas/laminas-filter
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)

Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/Solver.php on line 223

Check https://getcomposer.org/doc/articphp -i | grep memory_limit how to handle out of memory errors.

My PHP ini file is set to 1GB of memory_limit so this really shouldn't be happening.

@emergingdzns
Copy link
Author

A bit more testing here...

I found some help about using "COMPOSER_MEMORY_LIMIT=-1" before running composer require. This fixed the problem with installing but immediately after installing ONLY Luminas I again get the AddonLoader error. I'm going to try building a new default Laravel instance and add Luminas to it and turn it into a service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants