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

Serialization of 'Closure' is not allowed #6

Closed
Lansoweb opened this Issue Jan 24, 2015 · 16 comments

Comments

Projects
None yet
5 participants
@Lansoweb
Copy link
Contributor

Lansoweb commented Jan 24, 2015

After a day trying to found a bug in a project, i found that the Z-Ray Form collector was causing my problem. When i try to open any page with a form i get the error:

Serialization of 'Closure' is not allowed

#0 .../vendor/zendframework/zendframework/library/Zend/Stdlib/PriorityQueue.php(188): serialize(Array)
#1 [internal function]: Zend\Stdlib\PriorityQueue->serialize()
#2 .../vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject.php(333): serialize(Array)
#3 .../vendor/zendframework/zendframework/library/Zend/Form/View/Helper/Form.php(73): Zend\Stdlib\ArrayObject->serialize()
#4 .../vendor/zendframework/zendframework/library/Zend/Form/View/Helper/Form.php(73): Zend\Form\View\Helper\Form->openTag(Object(Zend\Form\Form))

The problem is with the line 106 from zray.php:

 public function storeFormInfoExit($context, &$storage) {
            $form = $context["functionArgs"][0]; // form object

        $storage['forms'][get_class($form)] = array(   'label'      => $form->getLabel(),
                                                       'elements'   => $form->getElements(), // <--- HERE
                                                       'attributes' => $form->getAttributes(),
                                                       'messages'   => $form->getMessages());
        }

If i comment the 'elements' key, it works. Of course, if i disable Z-Ray or "Close for session", it works.

I created a loop inside this function to see the form elements, but couldn't find any problems so far:

name: Zend\Form\Element\Text
csrf: Zend\Form\Element\Csrf
submit: Zend\Form\Element\Button
cancel: Zend\Form\Element\Button

This began yesterday, when i upgraded my ZendServer from 8.0 (beta) to 8.0.1. Already try a clean install, installed version 5.5 and 5.6, nothing.

Will try to investigate further ...

Any suggestions?

Regards,
Leandro Silva

@Lansoweb

This comment has been minimized.

Copy link
Contributor Author

Lansoweb commented Jan 24, 2015

The problem seems to be with the Csrf element. If i remove it from the form, the problem disappears.

I'm adding with:

$form->add([
            'type' => 'Zend\Form\Element\Csrf',
            'name' => 'csrf'
        ]);

If i var_export it:

Zend\Form\Element\Csrf::__set_state(array(
   'attributes' => 
  array (
    'type' => 'hidden',
    'name' => 'csrf',
  ),
   'csrfValidatorOptions' => 
  array (
  ),
   'csrfValidator' => NULL,
   'label' => NULL,
   'labelAttributes' => 
  array (
  ),
   'labelOptions' => 
  array (
  ),
   'messages' => 
  array (
  ),
   'options' => 
  array (
  ),
   'value' => NULL,
))

The problem is that when it's serialized, the SessionContainer inside the CsrfValidator is being serialized too.

I don't think adding a __sleep() method to the CsrfValidator to solve this problem a good practice. Maybe in the zray.php, iterate through the elements, and if a csrf element is found, remove it (or it's validator) and return it after?

Any ideias?

Regards,
Leandro Silva

@Lansoweb

This comment has been minimized.

Copy link
Contributor Author

Lansoweb commented Jan 25, 2015

Found another problem today. Some forms have a select element with doctrine entities (User belongs to a Client) and i get:

You cannot serialize or unserialize PDO instances

I think we won't be able (nor should) to individually handle each module out there, just ZF2 itself.

Maybe a try/catch?

@amitdar

This comment has been minimized.

Copy link
Contributor

amitdar commented Jan 26, 2015

Thanks for the PR, approved of course.
About the serialize issue we will investigate what's the best solution to prevent such cases in the future,

@amitdar amitdar closed this Jan 26, 2015

@Lansoweb

This comment has been minimized.

Copy link
Contributor Author

Lansoweb commented Jan 26, 2015

Glad to help! Thank you.

@chielsen

This comment has been minimized.

Copy link

chielsen commented Feb 2, 2015

I just spent a day trying to figure out what was going on, but this issue also exists on ZF1.
I'm not sure how exactly, but it is very annoying.

The problem is the serialization does not give a proper backtrace. More like a last reference to code executed after which the session saving started. Since i disabled all my session handling it was driving me crazy. I'm sure it's something in Z-ray because when it's disabled it does not happing (explains why with debugging everything was fine.. making me more go nuts).

@Lansoweb

This comment has been minimized.

Copy link
Contributor Author

Lansoweb commented Feb 2, 2015

@chielsen Hi! Yes, it's a relatively new product, so it will take some time to tune it and fix there kind of bug. But the best option is to post it here, so the developers (and community) can fix them. I suggest you open a new issue in the https://github.com/zend-server-extensions/Z-Ray-ZF1 about it.
Thanks for the feedback!

@skors

This comment has been minimized.

Copy link

skors commented Apr 10, 2015

hi,

is there any progress in this issue? We have the same problems here (Csrf Form Element).
😢

@Lansoweb

This comment has been minimized.

Copy link
Contributor Author

Lansoweb commented Apr 10, 2015

@skors Hi! It's already merged to the master branch, but your local copy (Zend Server) may be outdated. I suggest you download this https://github.com/zend-server-extensions/Z-Ray-ZF2/blob/master/zray.php and overwrite your local copy.

@skors

This comment has been minimized.

Copy link

skors commented Apr 10, 2015

@Lansoweb thanks. you are absolutely right. Using Zend Server 8.0.2 still has an outdated version packed. Replacing with the current file from this repository works. thx, community works. but still complicated to find this issue resolved here ;-)

@Lansoweb

This comment has been minimized.

Copy link
Contributor Author

Lansoweb commented Apr 10, 2015

@skors Glad to help :-) Agreed. @amitdar I'd suggest that the Z-Ray extensions could be updated through the UI, like the Libraries.

@skors

This comment has been minimized.

Copy link

skors commented Apr 10, 2015

@amitdar @Lansoweb This would be really nice!

@amitdar

This comment has been minimized.

Copy link
Contributor

amitdar commented Apr 11, 2015

@Lansoweb @skors again thank you for your help with this fix, it really helps the community. In the next release of Zend Server the closure bug was fixed in the core so stay tuned.
Also, we have a new mechanism for extensions life cycle just like libraries - deploy (cluster supported), remove, update and check for updates online. It would be very easy to install new extensions and keep your system update with the latest version.

@Lansoweb

This comment has been minimized.

Copy link
Contributor Author

Lansoweb commented Apr 11, 2015

@amitdar Great news!! Thanks!

jamesj2 added a commit to jamesj2/Z-Ray-ZF1 that referenced this issue Apr 20, 2015

dont serialize pdo instances
Port makeArraySerializable() from ZF2/zray.php.  See zend-server-extensions/Z-Ray-ZF2#6 (comment).  Incorporated ArrayUtils::iteratorToArray because I don't know of a ZF1 alternative.
@Sanymedia

This comment has been minimized.

Copy link

Sanymedia commented Apr 24, 2015

Hello,

I updated by zray.php for ZF2, but, i become the Same error:

You cannot serialize or unserialize PDO instances

With Zend Server 8.0.2 and PHP 5.6, and zray.php from this Repository...

@Lansoweb

This comment has been minimized.

Copy link
Contributor Author

Lansoweb commented Apr 24, 2015

@Sanymedia yes, this error stills occurs with forms with doctrine entities, there is no fix for that yet. Please, "close zray for session" for this page.

@Lansoweb

This comment has been minimized.

Copy link
Contributor Author

Lansoweb commented May 15, 2015

Just as a follow up, in the new Zend Server 8.1 (EA), these errors are catched and no longer break the page, but appear as an error in the Z-Ray bar. Great work!

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