I am getting the following error on .../checkout/ID/order_information page after submitting payment details for Review.

Exception: Serialization of 'Closure' is not allowed in serialize() (line 14 of core/lib/Drupal/Component/Serialization/PhpSerialize.php).

I have tried to catch the exception with a try/catch block, but it always gives that fatal error, if I unchecked My billing information is the same as my shipping information checkbox in the Payment information form.

I am using my custom payment method module for payment. Where should I look in the code to find what is causing the fatal error?

__construct() method :-

public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, PaymentTypeManager $payment_type_manager, PaymentMethodTypeManager $payment_method_type_manager, TimeInterface $time) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $payment_type_manager, $payment_method_type_manager, $time);

  if ($this->getMode() === 'test') {
    $url = "url given here";
  else {
    $url = "url given here";

  try {
    $this->soapClient = new SoapClient($url);
  catch (SoapFault $e) {
    throw new PaymentGatewayException($e->getMessage());
  • 2
    Do you have a __construct() method of your class? If so, please add it to the post. It may be causing your issue.
    – Jaypan
    May 25, 2020 at 14:39
  • PhpSerialize.php is drupal's core file, no construct method for PhpSerialize class
    – softech
    May 26, 2020 at 6:29
  • No, in your custom module
    – Jaypan
    May 26, 2020 at 6:38
  • Sorry, I have updated my question
    – softech
    May 26, 2020 at 8:04
  • This is probably because you are adding (possibly indirectly) something to a form that can't be serialized. In case it's your custom payment method class I suggest refactoring so the soap client is initialized lazily instead of in the constructor. May 26, 2020 at 10:25

1 Answer 1


I believe this comes from loading a connection in the SOAP client, and storing it in memory with $this->soapClient. The problem is that the soap client cannot be serialized. Serialization is the process of turning something into a string, generally so it can be stored in a databse or a file or something, to be retrieved later. The SOAP connection is not something that can be stored, which is why you are facing the issue.

You could potentially store the SOAP client in the construct method, then make the connection using the client when you actually need it. I'm guessing that the client, without a connection, can probably be serialized. I may be wrong though, and you may need to call the soap client dynamically every time you need it.

  • taking out $this->soapClient = new SoapClient($url); from construct method has fixed this issue for now
    – softech
    May 27, 2020 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.